Skip to content

Instantly share code, notes, and snippets.

@eshacker
eshacker / short_this_js.js
Created February 1, 2016 06:15
A very short study in this of JavaScript
function Namer(){
console.log(this instanceof Namer);
}
Namer(); // false
new Namer(); // true
Namer.call(Namer.prototype); // false
Namer.call(new Namer); // true true
Namer.call(Namer); // false
Namer.call(Object.create(Namer.prototype)); // true
@eshacker
eshacker / bind.js
Created February 1, 2016 08:43
A short tutorial on bind
var x = 1;
var A = {
x : 10,
get: function(){ return this.x; }
};
var a = A.get;
console.log(a()); // 1
@eshacker
eshacker / apply_and_call.js
Created February 1, 2016 09:00
Apply and Call in JavaScript
/* when there is no difference in apply and call */
// 1.
var func = function(arr, barr, carr){
this.arr = arr;
console.log(typeof(arr), arr.length, arr, barr, carr);
};
func.call(null, 1, 2, 3); // number undefined 1 2 3