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
if (DEBUG) { console.log('Debugging is starting'); } | |
// Results the reference error when debug.js is not loaded. | |
if (typeof DEBUG !== 'undefined' && DEBUG) { console.log('Debuggins is starting'); } | |
// This is safer. |
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 a() {} | |
var b = function() {} | |
typeof a; 'function' | |
typeof b; 'function' |
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
for (let c in b) { console.log( c ); }; // a | |
// Enumerable travels prototype chains. | |
for (let key in Object.keys( b )) { console.log( key ) }; // nothing prints out |
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 a = { a: 2, } | |
var b = Object.create( a ); | |
console.log( b ); // {} | |
console.log( b.a ); // 2 <- It got 2 from b's prototype chain | |
/* | |
b with prototypes | |
{ | |
__proto__: { | |
a: 2, | |
__proto__: { ... } |
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 mixin(sourceObj, targetObj) { | |
for (var key in sourceObj) { | |
if (!(key in targetObj)) { | |
targetObj[key] = sourceObj[key]; | |
} | |
} | |
return targetObj; | |
} | |
var Vehicle = { | |
engines: 1, |
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
class A { | |
public void ignition() { | |
System.out.println("A ignition"); | |
} | |
public void drive() { | |
this.ignition(); | |
System.out.println("A drive"); | |
} | |
} | |
class B extends A { |
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 myObject = { | |
a: 2, | |
b: 3, | |
}; | |
Object.defineProperty(myObject, Symbol.iterator, { | |
enumerable: false, | |
writable: false, | |
configurable: true, | |
value: function() { | |
var o = this; |
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 a = {}; | |
Object.defineProperty(a, 'a', { | |
value: 1, | |
writable: true, | |
enumerable: true, | |
configurable: true, | |
}); | |
Object.defineProperty(a, 'b', { | |
value: 2, | |
writable: true, |
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 a = { | |
a: 2, | |
}; | |
("a" in a); // true | |
("b" in a); // false | |
a.hasOwnProperty("a"); // true | |
a.hasOwnProperty("b"); // false | |
// in operation also consults object prototype. So compare following two linces |
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 a = { | |
get a() { | |
return 2; | |
} | |
} | |
Object.defineProperty(a, "b", { | |
get: function() { return this.a * 2 }, | |
enumerable: true, | |
}); | |
a.a; // 2 |