working on it ...

Filters

Explore Public Snippets

Sort by

Found 920 snippets matching: underscore

    public by micurs  6865995  355  9  18

    Typescript: passing a class member function as parameter to another function

    Typescript introduces the class construct and the concept of member functions. However if you try to pass a instance member function as parameter to another function the binding with the instance is lost. To solve this problem you can use the capability of javascript (and Typescript) to support closures on anonymous function (or lambda expressio
    ///<reference path='../types/node.d.ts'/>
    ///<reference path='../types/underscore.d.ts'/>
    
    import _ = require("underscore");
    
    class SomePeople {
      values : string[] = [ 'John', 'Mary', 'Peter'];
    
      out() {
        _.each( this.values, (v) => process.stdout.write( v + '\n') );
      }
    }
    // This function accept a function it will execute internally
    function outSomething( outFunc : () => any ) {
      outFunc();
    }
    
    var crowd = new SomePeople();
    
    // This won't work since the actual crowd instance binding will be lost
    outSomething( crowd.out );
    
    // This will work: the closure within the lambda expression retain the
    // crowd instance and its data
    outSomething( () => crowd.out() );
        

    public by micurs  7674  4  9  11

    Typescript + underscore: iterating through a collection property of a class

    In this example we define a signature interface (Students) to locate a student using a student ID. In the Course class we use property getters function to provide read only access to the class members. Finally we use underscore to iterate on the Students as it was an array. The example runs on node.js with Typescript 0.9.5
    ///<reference path='../types/node.d.ts'/>
    ///<reference path='../types/underscore.d.ts'/>
    
    import _ = require("underscore");
    
    function write(msg) {
        process.stdout.write(msg+'\n');
    }
    // Index Interface to locate a student given an id
    interface Students {
      [ studentId: number ] : Student;
    }
    
    class Student {
      private _id : number;
      private _name : string;
      private _lastName : string;
      constructor ( id: number, name : string, lastName : string ) {
        this._id = id;
        this._name = name;
        this._lastName = lastName;
      }
      // Property getters for Student
      get id() :number { return this._id; }
      get lastName() : string { return this._lastName; }
    }
    
    class Course {
      private title : string;
      _participants : Students = {};
    
      constructor( t : string ) {
        this.title = t;
      }
    
      addStudent( s: Student ) {
        this._participants[s.id] = s;
      }
      getStudent( sid: number ) : Student {
        return this._participants[sid];
      }
    
      // Property getter to retrieve the participants of a Course
      get participants() {
        return _.values(this._participants)    
      }
    
    }
    
    var c = new Course("Computer Science 101");
    c.addStudent(new Student(23,"Mark","Twain"));
    c.addStudent(new Student(100,"Albert","Einstein"));
    c.addStudent(new Student(120,"Isaac","Asimov"));
    
    _.each( c.participants , (s : Student) => write(s.lastName));
     

    public by micurs  3801  2  7  3

    Generate comma separated value string in Typescript using underscore _.reduce()

    Underscore work well with Typescript lambda syntax.
    import _ = require("underscore");
    
    var values: number[] = [ 5, 19, 64, 12, 45 ];
    
    var csv: string = 
     _.reduce( values, 
              ( acc: string, item ) => acc+= ','+item.toString() 
             );
         

    public by micurs  2762  2  9  7

    Execute javascript code at the end of a CSS transition

    Using JQuery you can easily bind a function to any event. CSS transitions on a given element trigger different event depending on the browser. You can capture all or write a small function that select the one working on the current browser. Here is how (using typescript and underscore):
    function getBrowserTransitionEvent( el : JQuery ) : string {
      var transitions = [ 
        { name: 'transition', value: 'transitionend' },
        { name: 'OTransition', value: 'oTransitionEnd' },
        { name: 'MozTransition', value: 'transitionend' },
        { name: 'WebkitTransition', value: 'webkitTransitionEnd' } ];
      var HTMLElement e = el.get();
      var t = _.find< { name: string; value: string }>( transitions , 
          (t) => e.style[t.name] !== undefined);
      return t !== undefined ? t.value : '';
    }
    
    
    // Here is how to use this:
    $('#myElement').bind( getBrowserTransitionEvent($('#myElement')),
      function() {
        alert('CSS transision is complete');
      });

    public by sTiLLiLL  1714  7  5  6

    some home-made "underscore" type constructs

    some home-made "underscore" type constructs: forEvery.js
    // my for-each thing
    
    function forEeach(array, action) {
        try {
            var len = array.length;
            for (var i = 0; i < len; i++)
                action(array[i]);
        } catch (e) {
            throw e;
        }
    }
    
    

    public by micurs  12305  4  10  4

    Typescript + underscore: serializing objects

    This little example runs on node.js and assumes you have the typescript type-definition file in the types subdirectory. The example defines two classes one representing a undergrad course in computer science and another one representing possible students for the course. Few things are interesting here: 1 - the overloading of the toString()
    ///<reference path='../types/node.d.ts'/>
    ///<reference path='../types/underscore.d.ts'/>
    
    import _ = require("underscore");
    
    function write(msg) {
        process.stdout.write(msg+'\n');
    }
    
    class Student {
      firstName : string;
      lastName : string;
    
      constructor( n: string, v: string ) {
        this.firstName = n;
        this.lastName = v;
      }
    
      toString() : string {
        return '[ ' + this.firstName + ' ' + this.lastName + ' ]';
      }
    }
    
    class Class {
      title : string = "Computer Science 101";
      participants : Student[] = new Array();
    
      addStudent( s : Student ) : any {
        this.participants.push(s);
      }
    
      toString() : string {
        return this.title + '\n\t' 
              + _.reduce( this.participants, (acc,s) => acc += '\n\t'+ s );
      }
    
    }
    
    var firstSemesterClass : Class = new Class();
    
    firstSemesterClass.addStudent( new Student("John","Smith"));
    firstSemesterClass.addStudent( new Student("Frank","Gehry"));
    
    write( firstSemesterClass );
    
        

    external by Github  251  0  3  0

    very best job <a href=" https://archive.is/HIjNj ">prednisone medrol pack dosage</a> Secretary of State John Kerry spoke to Greek Foreign Minister Nikos Kotzias by telephone on Friday to congratulate him on his appointment and underscore "the United S...

    very best job prednisone medrol pack dosage Secretary of State John Kerry spoke to Greek Foreign Minister Nikos Kotzias by telephone on Friday to congratulate him on his appointment and underscore "the United States' interest in continued close bilateral cooperation with Greece," said a senior State Department official speaking on condition of ano
    very best job <a href=" https://archive.is/HIjNj ">prednisone medrol pack dosage</a>  Secretary of State John Kerry spoke to Greek Foreign Minister Nikos Kotzias by telephone on Friday to congratulate him on his appointment and underscore "the United States' interest in continued close bilateral cooperation with Greece," said a senior State Department official speaking on condition of anonymity
     <a href=" http://estrace.buyiri.top/ ">estradiol 1mg tablet price</a>  The AIIB was launched in Beijing last year to spur investment in Asia in transportation, energy, telecommunications and other infrastructure
     <a href=" http://www.presentenamorado.com.br/can-promethazine-25-mg-tablet-get-you-high/ ">promethazine codeine 6.25-10 how much to get high</a>  Saturday found a woman suffering from gunshot wounds in the area of Charlotte and Blue Hill Avenues in the Dorchester neighborhood.
     
    
    

    external by Khoa Nguyen  150  0  2  0

    Should integrate underscore string into underscore?

    Should integrate underscore string into underscore?: should-integrate-underscore-string-into-underscore.md
    When you need using functions from [_.string] for [_.js] chaining 
    ```javascript
    _.mixin(s.exports());
    ```
    
    But I think you should do if using both because chaining with [_.string] will soon occur. Unless you want keep [_.string] independently and no chaining with [_.string].
    
    [_.string]: https://github.com/epeli/underscore.string
    [_.js]: http://underscorejs.org/
    
    

    external by Malte N  183  0  2  0

    This is just a yaml "library" of minecraft items, written for those who have to translate item ids into english names. If an item has a data value, it is written behind an underscore "_".

    This is just a yaml "library" of minecraft items, written for those who have to translate item ids into english names. If an item has a data value, it is written behind an underscore "_".: materials.yml
    1: Stone
    2: Grass
    3: Dirt
    4: Cobblestone
    5: Wooden Plank (Oak)
    5_1: Wooden Plank (Spruce)
    5_2: Wooden Plank (Birch)
    5_3: Wooden Plank (Jungle)
    6: Sapling (Oak)
    6_1: Sapling (Spruce)
    6_2: Sapling (Birch)
    6_3: Sapling (Jungle)
    7: Bedrock
    8: Water
    9: Water (No Spread)
    10: Lava
    11: Lava (No Spread)
    12: Sand
    13: Gravel
    14: Gold Ore
    15: Iron Ore
    16: Coal Ore
    17: Wood (Oak)
    17_1: Wood (Spruce)
    17_2: Wood (Birch)
    17_3: Wood (Jungle)
    18: Leaves (Oak)
    18_1: Leaves (Spruce)
    18_2: Leaves (Birch)
    18_3: Leaves (Jungle)
    19: Sponge
    20: Glass
    21: Lapis Lazuli Ore
    22: Lapis Lazuli Block
    23: Dispenser
    24: Sandstone
    24_1: Sandstone (Chiseled)
    24_2: Sandstone (Smooth)
    25: Note Block
    26: Bed (Block)
    27: Powered Rail
    28: Detector Rail
    29: Sticky Piston
    30: Cobweb
    31: Tall Grass (Dead Shrub)
    31_1: Tall Grass
    31_2: Tall Grass (Fern)
    32: Dead Shrub
    33: Piston
    34: Piston (Head)
    35: Wool
    35_1: Orange Wool
    35_2: Magenta Wool
    35_3: Light Blue Wool
    35_4: Yellow Wool
    35_5: Lime Wool
    35_6: Pink Wool
    35_7: Gray Wool
    35_8: Light Gray Wool
    35_9: Cyan Wool
    35_10: Purple Wool
    35_11: Blue Wool
    35_12: Brown Wool
    35_13: Green Wool
    35_14: Red Wool
    35_15: Black Wool
    36: Piston (Moving)
    37: Dandelion
    38: Rose
    39: Brown Mushroom
    40: Red Mushroom
    41: Block of Gold
    42: Block of Iron
    43: Stone Slab (Double)
    43_1: Sandstone Slab (Double)
    43_2: Wooden Slab (Double)
    43_3: Cobblestone Slab (Double)
    43_4: Brick Slab (Double)
    43_5: Stone Brick Slab (Double)
    43_6: Nether Brick Slab (Double)
    43_7: Quartz Slap (Double)
    43_8: Smooth Stone Slab (Double)
    43_9: Smooth Sandstone Slab (Double)
    44: Stone Slab
    44_1: Sandstone Slab
    44_2: Wooden Slab
    44_3: Cobblestone Slab
    44_4: Brick Slab
    44_5: Stone Brick Slab
    44_6: Nether Brick Slab
    44_7: Quartz Slab
    45: Brick
    46: TNT
    47: Bookcase
    48: Moss Stone
    49: Obsidian
    50: Torch
    51: Fire
    52: Mob Spawner
    53: Wooden Stairs (Oak)
    54: Chest
    55: Redstone Wire
    56: Diamond Ore
    57: Block of Diamond
    58: Workbench
    59: Wheat (Crop)
    60: Farmland
    61: Furnace
    62: Furnace (Smelting)
    63: Sign (Block)
    64: Wood Door (Block)
    65: Ladder
    66: Rail
    67: Cobblestone Stairs
    68: Sign (Wall Block)
    69: Lever
    70: Stone Pressure Plate
    71: Iron Door (Block)
    72: Wooden Pressure Plate
    73: Redstone Ore
    74: Redstone Ore (Glowing)
    75: Redstone Torch (Off)
    76: Redstone Torch
    77: Button (Stone)
    78: Snow
    79: Ice
    80: Snow Block
    81: Cactus
    82: Clay Block
    83: Sugar Cane (Block)
    84: Jukebox
    85: Fence
    86: Pumpkin
    87: Netherrack
    88: Soul Sand
    89: Glowstone
    90: Portal
    91: Jack-O-Lantern
    92: Cake (Block)
    93: Redstone Repeater (Block Off)
    94: Redstone Repeater (Block On)
    95: Locked Chest
    96: Trapdoor
    97: Silverfish Stone
    97_1: Silverfish Cobblestone
    97_2: Silverfish Stone Brick
    98: Stone Brick
    99: Brown Mushroom (Block)
    100: Red Mushroom (Block)
    101: Iron Bars
    102: Glass Pane
    103: Melon (Block)
    104: Pumpkin Vine
    105: Melon Vine
    106: Vines
    107: Fence Gate
    108: Brick Stairs
    109: Stone Brick Stairs
    110: Mycelium
    111: Lily Pad
    112: Nether Brick
    113: Nether Brick Fence
    114: Nether Brick Stairs
    115: Nether Wart
    116: Enchantment Table
    117: Brewing Stand (Block)
    118: Cauldron (Block)
    119: End Portal
    120: End Portal Frame
    121: End Stone
    122: Dragon Egg
    123: Redstone Lamp
    124: Redstone Lamp (On)
    125: Oak-Wood Slab (Double)
    125_1: Spruce-Wood Slab (Double)
    125_2: Birch-Wood Slab (Double)
    125_3: Jungle-Wood Slab (Double)
    126: Oak-Wood Slab
    126_1: Spruce-Wood Slab
    126_2: Birch-Wood Slab
    126_3: Jungle-Wood Slab
    127: Coca Plant
    128: Sandstone Stairs
    129: Emerald Ore
    130: Ender Chest
    131: Tripwire Hook
    132: Tripwire
    133: Block of Emerald
    134: Wooden Stairs (Spruce)
    135: Wooden Stairs (Birch)
    136: Wooden Stairs (Jungle)
    137: Command Block
    138: Beacon
    139: Cobblestone Wall
    140: Flower Pot (Block)
    141: Carrot (Crop)
    142: Potatoes (Crop)
    143: Button (Wood)
    144: Head Block (Skeleton)
    144_1: Head Block (Wither)
    144_2: Head Block (Zombie)
    144_3: Head Block (Steve)
    144_4: Head Block (Creeper)
    145: Anvil
    145_1: Anvil (Slightly Damaged)
    145_2: Anvil (Very Damaged)
    146: Trapped Chest
    147: Weighted Pressure Plate (Light)
    148: Weightes Pressure Plate (Heavy)
    149: Redstone Comperator (Off)
    150: Redstone Comperator (On)
    151: Daylight Sensor
    152: Block of Redstone
    153: Nether Quartz Ore
    154: Hopper
    155: Quartz Block
    155_1: Chiseled Quartz Block
    155_2: Pillar Quartz Block
    156: Quartz Stairs
    157: Activator Rail
    158: Dropper
    159: Stained Clay (White)
    159_1: Stained Clay (Orange)
    159_2: Stained Clay (Magenta)
    159_3: Stained Clay (Light Blue)
    159_4: Stained Clay (Yellow)
    159_5: Stained Clay (Lime)
    159_6: Stained Clay (Pink)
    159_7: Stained Clay (Gray)
    159_8: Stained Clay (Light Gray)
    159_9: Stained Clay (Cyan)
    159_10: Stained Clay (Purple)
    159_11: Stained Clay (Blue)
    159_12: Stained Clay (Brown)
    159_13: Stained Clay (Green)
    159_14: Stained Clay (Red)
    159_15: Stained Clay (Black)
    170: Hay Bale
    171: Carpet (White)
    171_1: Carpet (Orange)
    171_2: Carpet (Magenta)
    171_3: Carpet (Light Blue)
    171_4: Carpet (Yellow)
    171_5: Carpet (Lime)
    171_6: Carpet (Pink)
    171_7: Carpet (Gray)
    171_8: Carpet (Light Gray)
    171_9: Carpet (Cyan)
    171_10: Carpet (Purple)
    171_11: Carpet (Blue)
    171_12: Carpet (Brown)
    171_13: Carpet (Green)
    171_14: Carpet (Red)
    171_15: Carpet (Black)
    172: Hardened Clay
    173: Block of Coal
    256: Iron Shovel
    257: Iron Pickaxe
    258: Iron Axe
    259: Flint and Steel
    260: Apple
    261: Bow
    262: Arrow
    263: Coal
    263_1: Charcoal
    264: Diamond Gem
    265: Iron Ingot
    266: Gold Ingot
    267: Iron Sword
    268: Wooden Sword
    269: Wooden Shovel
    270: Wooden Pickaxe
    271: Wooden Axe
    272: Stone Sword
    273: Stone Shovel
    274: Stone Pickaxe
    275: Stone Axe
    276: Diamond Sword
    277: Diamond Shovel
    278: Diamond Pickaxe
    279: Diamond Axe
    280: Stick
    281: Bowl
    282: Mushroom Stew
    283: Gold Sword
    284: Gold Shovel
    285: Gold Pickaxe
    286: Gold Axe
    287: String
    288: Feather
    289: Gunpowder
    290: Wooden Hoe
    291: Stone Hoe
    292: Iron Hoe
    293: Diamond Hoe
    294: Gold Hoe
    295: Wheat Seeds
    296: Wheat
    297: Bread
    298: Leather Helmet
    299: Leather Chestplate
    300: Leather Leggings
    301: Leather Boots
    302: Chainmail Helmet
    303: Chainmail Chestplate
    304: Chainmail Leggings
    305: Chainmail Boots
    306: Iron Helmet
    307: Iron Chestplate
    308: Iron Leggings
    309: Iron Boots
    310: Diamond Helmet
    311: Diamond Chestplate
    312: Diamond Leggings
    313: Diamond Boots
    314: Gold Helmet
    315: Gold Chestplate
    316: Gold Leggings
    317: Gold Boots
    318: Flint
    319: Raw Pokchop
    320: Cooked Porkchop
    321: Painting
    322: Golden Apple
    322_1: Enchanted Golden Apple
    323: Sign
    324: Wooden Door
    325: Bucket
    326: Bucket (Water)
    327: Bucket (Lava)
    328: Minecart
    329: Saddle
    330: Iron Door
    331: Redstone Dust
    332: Snowball
    333: Boat
    334: Leather
    335: Bucket (Milk)
    336: Clay Brick
    337: Clay
    338: Sugar Cane
    339: Paper
    340: Book
    341: Slime Ball
    342: Storage Minecart
    343: Powered Minecart
    344: Egg
    345: Compass
    346: Fishing Rod
    347: Watch
    348: Glowstone Dust
    349: Raw Fish
    350: Cooked Fish
    351: Ink Sack
    351_1: Rose Red Dye
    351_2: Cactus Green Dye
    351_3: Coca Bean
    351_4: Lapis Lazuli
    351_5: Purple Dye
    351_6: Cyan Dye
    351_7: Light Gray Dye
    351_8: Gray Dye
    351_9: Pink Dye
    351_10: Lime Dye
    351_11: Dandelion Yellow Dye
    351_12: Light Blue Dye
    351_13: Magenta Dye
    351_14: Orange Dye
    351_15: Bone Meal
    352: Bone
    353: Sugar
    354: Cake
    355: Bed
    356: Redstone Repeater
    357: Cookie
    358: Map
    359: Shears
    360: Melon (Slice)
    361: Pumpkin Seeds
    362: Melon Seeds
    363: Raw Beef
    364: Steak
    365: Raw Chicken
    366: Cooked Chicken
    367: Rotten Flesh
    368: Ender Pearl
    369: Blaze Rod
    370: Ghast Tear
    371: Gold Nugget
    372: Nether Wart Seeds
    373: Water Bottle
    373_16: Awkward Potion
    373_32: Thick Potion
    373_64: Mundane Potion
    373_8193: Regeneration Potion (0:45)
    373_8194: Swiftness Potion (3:00)
    373_8195: Fire Resistance Potion (3:00)
    373_8196: Poison Potion (0:45)
    373_8197: Healing Potion
    373_8198: Night Vision Potion (3:00)
    373_8200: Weakness Potion (1:30)
    373_8201: Strength Potion (3:00)
    373_8202: Slowness Potion (1:30)
    373_8204: Harming Potion
    373_8206: Invisibility Potion (3:00)
    373_8225: Regeneration Potion II (0:22)
    373_8226: Swiftness Potion II (1:30)
    373_8228: Poison Potion II (0:22)
    373_8229: Healing Potion II
    373_8233: Strength Potion II (1:30)
    373_8236: Harming Potion II
    373_8257: Regeneration Potion (2:00)
    373_8258: Swiftness Potion (8:00)
    373_8259: Fire Resistance Potion (8:00)
    373_8260: Poison Potion (2:00)
    373_8262: Night Vision Potion (8:00)
    373_8264: Weakness Potion (4:00)
    373_8265: Strength Potion (8:00)
    373_8266: Slowness Potion (4:00)
    373_8270: Invisibility Potion (8:00)
    373_8289: Regeneration Portion II (1:00)
    373_8290: Swiftness Potion II (1:00)
    373_8292: Poison Potion II (1:00)
    373_8297: Strength Potion II (4:00)
    373_16385: Regeneration Splash (0:33)
    373_16386: Swiftness Splash (2:15)
    373_16387: Fire Resistance Splash (2:15)
    373_16388: Poison Splash (0:33)
    373_16389: Healing Splash
    373_16390: Night Vision Splash (2:15)
    373_16392: Weakness Splash (1:07)
    373_16393: Strength Splash (2:15)
    373_16394: Slowness Splash (1:07)
    373_16396: Harming Splash
    373_16398: Invisibility Splash (2:15)
    373_16417: Regeneration Splash II (0:16)
    373_16418: Swiftness Splash II (1:07)
    373_16420: Poison Splash II (0:16)
    373_16421: Healing Splash II
    373_16425: Strength Splash (1:07)
    373_16428: Harming Splash II
    373_16449: Regemeration Splash (1:30)
    373_16450: Swiftness Splash (6:00)
    373_16451: Fire Resistance Splash (6:00)
    373_16452: Poison Splash (1:30)
    373_16454: Night Vision Splash (6:00)
    373_16456: Weakness Splash (3:00)
    373_16457: Strength Splash (6:00)
    373_14458: Slowness Splash (3:00)
    373_16462: Invisibility Splash (6:00)
    373_16481: Regeneration Splash II (0:45)
    373_16482: Swiftness Splash II (3:00)
    373_16484: Poison Splash II (0:45)
    373_16489: Strength Splash II (3:00)
    374: Glass Bottle
    375: Spider Eye
    376: Fermented Spider Eye
    377: Blaze Powder
    378: Magma Cream
    379: Brewing Stand
    380: Cauldron
    381: Eye of Ender
    382: Glistering Melon (Slice)
    383_50: Spawn Egg (Creeper)
    383_51: Spawn Egg (Skeleton)
    383_52: Spawn Egg (Spider)
    383_54: Spawn Egg (Zombie)
    383_55: Spawn Egg (Slime)
    383_56: Spawn Egg (Ghast)
    383_57: Spawn Egg (Zombie Pigmen)
    383_58: Spawn Egg (Endermen)
    383_59: Spawn Egg (Cave Spider)
    383_60: Spawn EGg (Silverfish)
    383_61: Spawn Egg (Blaze)
    383_62: Spawn Egg (Magma Cube)
    383_65: Spawn Egg (Bat)
    383_66: Spawn Egg (Witch)
    383_90: Spawn Egg (Pig)
    383_91: Spawn Egg (Sheep)
    383_92: Spawn Egg (Cow)
    383_93: Spawn Egg (Chicken)
    383_94: Spawn Egg (Squid)
    383_95: Spawn Egg (Wolf)
    383_96: Spawn Egg (Mooshroom)
    383_98: Spawn Egg (Ocelot)
    383_100: Spawn Egg (Horse)
    383_120: Spawn Egg (Villager)
    384: Bottle of Enchanting
    385: Fire Charge
    386: Book and Quill
    387: Written Book
    388: Emerald
    389: Item Frame
    390: Flower Pot
    391: Carrot
    392: Potato
    393: Baked Potato
    394: Poisonous Potato
    395: Empty Map
    396: Golden Carrot
    397: Head (Skeleton)
    397_1: Head (Wither)
    397_2: Head (Zombie)
    397_3: Head (Steve)
    397_4: head (Creeper)
    398: Carrot on a Stick
    399: Nether Star
    400: Pumpkin Pie
    401: Firework Rocket
    402: Firework Star
    403: Enchanted Book
    404: Redstone Comperator
    405: Nether Brick (Item)
    406: Nether Quartz
    407: TNT Minecart
    408: Hopper Minecart
    417: Iron Horse Armor
    418: Gold Horse Armor
    419: Diamond Horse Armor
    420: Lead
    421: Name Tag
    2256: Music Disk (13)
    2257: Music Disk (Cat)
    2258: Music Disk (Blocks)
    2259: Music Disk (Chirp)
    2260: Music Disk (Far)
    2261: Music Disk (Mall)
    2262: Music Disk (Mellohi)
    2263: Music Disk (Stal)
    2264: Music Disk (Strad)
    2265: Music Disk (Ward)
    2266: Music Disk (11)
    2267: Music Disk (Wait)'
    
    

    external by Michael Benin  171  0  2  0

    Extending underscore to extend objects' functions with this._super

    Extending underscore to extend objects' functions with this._super: gistfile1.js
    // Description:
    // Adds this._super method to objects that are extended and have the
    // same function, keeps original function as reference on this._super
    
    var _ = require('underscore');
    
    _.extendWithSuper = function(obj) {
      if (!_.isObject(obj)) return obj;
      var source, prop;
      for (var i = 1, length = arguments.length; i < length; i++) {
        source = arguments[i];
        for (prop in source) {
    
          if (hasOwnProperty.call(source, prop)) {
            // check to see if both methods are functions
            if(_.isFunction(source[prop]) && _.isFunction(obj[prop])){
    
              var Class = function(){
                this._super = obj[prop];
              };
    
              var tmpClass = new Class();
    
              obj[prop] = function(){
                return source[prop].apply(tmpClass, _.toArray(arguments));
              };
    
              obj[prop].prototype = source[prop].prototype;
    
            } else {
              obj[prop] = source[prop];
            }
          }
        }
      }
      return obj;
    };
    
    var events = {
      click: function(){
        console.log('clicked original');
      }
    };
    
    var events2 = {
      click: function(){
        this._super();
        console.log('clicked inherited');
      }
    };
    
    var events3 = _.extendWithSuper(events, events2);
    
    events3.click();
    // clicked original
    // clicked inherited
    // undefined
    
    
    • Public Snippets
    • Channels Snippets