This file contains 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 test = function(key, value) { | |
a = {foo:{bar:{baz:"placeholder"}}}; | |
a.foo.bar.baz = {}; //creating a new object as `baz` value then assign | |
a.foo.bar.baz[key] = value; | |
console.log(JSON.stringify(a)); | |
}; | |
test("Jon", "Dough"); |
This file contains 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
/* | |
typeof is a construct that "returns" the primitive type of whatever you pass it. | |
instanceof tests to see if the right operand appears anywhere in the prototype chain of the left. | |
*/ | |
var test = require('tape'); | |
test('typeof vs instanceof tests', function (t) { | |
t.plan(13); |
This file contains 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
function Apple (type) { | |
this.type = type; | |
this.color = "red"; | |
} | |
Apple.prototype.getInfo = function() { | |
return this.color + ' ' + this.type + ' apple'; | |
}; | |
var apple = new Apple('macintosh'); |
This file contains 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
test = require("tape"); | |
function addMethod(object, name, fn){ | |
object._store = object._store || {}; | |
object._store[name] = object._store[name] || {}; | |
object._store[name][fn.length] = fn; | |
object[name] = function() { | |
if(this._store[name][arguments.length]) | |
return this._store[name][arguments.length].apply(this, arguments); | |
}; |
This file contains 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
test = require('tape'); | |
// Basic module with closure | |
var Module = (function () { | |
var my = {}, | |
privateVariable = 1; | |
function setPrivateMethod(val) { | |
privateVariable = val; |
This file contains 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 elasticsearch = require('elasticsearch'); | |
var client = elasticsearch.Client({ | |
hosts: [ | |
'localhost:9200' | |
] | |
}); | |
var tk = { | |
_bulkArray: function(idx, type, data) { |
This file contains 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 arr = [1,2,3,4]; | |
var res= arr.join(' '); |
This file contains 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
npm view module_name versions |
This file contains 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
window.onload = function() { | |
doSomethingElse(); | |
}; |
This file contains 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
function personContainer() { | |
var person = { | |
name: "James Smith", | |
hello: function() { | |
console.log(this.name + " says hello " + arguments[1]); | |
} | |
} | |
person.hello.apply(person, arguments); | |
} | |
personContainer("world", "mars"); // output: "James Smith says hello mars", note: arguments[0] = "world" , arguments[1] = "mars" |
OlderNewer