This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Zoo = function(animals) { | |
| this.animals = animals; | |
| }; | |
| Zoo.prototype = { | |
| bipeds: function() { | |
| return this.legFilter(2); | |
| }, | |
| quadrupeds: function() { | |
| return this.legFilter(4); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // recursive reimplementation of JSON.stringify | |
| var stringifyJSON = function(obj) { | |
| // null | |
| if (obj === null) { | |
| return "null"; | |
| } | |
| // unstringifiable - functions and undefined | |
| if (obj === undefined || obj.constructor === Function) { return; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var getElementsByClassName = function(className, node) { | |
| var matches = []; | |
| // top of node tree or default to body | |
| node = node || document.body; | |
| // get all classNames of node | |
| var nodeClasses = node.className.split(" "); | |
| // push node if node has className in classList |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var parseJSON = function(json) { | |
| // setup | |
| var idx = 0; | |
| var cc = ' '; | |
| var escapee = { | |
| '"': '"', | |
| '\\': '\\', | |
| '/': '/', | |
| b: '\b', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Example = function() { | |
| var example = Object.create(exampleMethods); | |
| example.extraProp1 = "Example Property Value"; | |
| return example; | |
| }; | |
| var exampleMethods = { | |
| exampleGet: function() { | |
| return this.extraProp1; | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Example = function() { | |
| var example = {}; | |
| var extraState = "Example Property Value"; | |
| example.exampleGet = function() { | |
| return extraState; | |
| }; | |
| example.exampleSet = function(value) { | |
| extraState = value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Example = function() { | |
| this.extraProp1 = "Example Property Value"; | |
| }; | |
| Example.prototype.exampleGet = function() { | |
| return this.extraProp1; | |
| }; | |
| Example.prototype.exampleSet = function(value) { | |
| this.extraProp1 = value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var HashTable = function() { | |
| this._limit = 8; // choose any size of hash table bucket limit | |
| this._count = 0; | |
| this._storage = []; | |
| }; | |
| HashTable.prototype.insert = function(k, v) { | |
| var i = this._getHashIndex(k, this._limit); | |
| this._checkLimit(i); // make sure hashidx is in bounds | |
| var bucket = this._storage[i]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Tree = function(value) { | |
| var newTree = {}; | |
| newTree.value = value; | |
| newTree.children = []; | |
| _.extend(newTree, treeMethods); | |
| return newTree; | |
| }; | |
| var treeMethods = {}; |
OlderNewer