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 obj11 = Object.create(Object.prototype, { | |
foo : { | |
value : 27 | |
}, | |
bar : { | |
value : 39, | |
enumerable : true | |
} | |
}); |
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 obj10 = { | |
x : 1, | |
y : 2, | |
z : 3 | |
}; | |
var arr1 = ['a', 'b', 'c']; | |
Object.keys( obj10 ); // returns ["x", "y", "z"] | |
Object.keys( arr1 ); // returns ["0", "1", "2"] |
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 obj8 = {}; | |
Object.defineProperties(obj8, { | |
foo : { | |
value : 100, | |
configurable : false, | |
enumerable : true | |
}, | |
bar : { | |
value : 300, |
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 obj8 = {}; | |
Object.defineProperties(obj8, { | |
foo : { | |
value : 100, | |
configurable : false, | |
enumerable : true | |
}, | |
bar : { | |
value : 300, |
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 obj4 = {}; // create a new empty object | |
Object.defineProperty(obj4, 'x', { | |
value : 'Some generic string', | |
writable : true, | |
enumerable : true, | |
configurable : true | |
}); | |
obj4.x; // returns "Some generic string" |
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
// Object.getPrototypeOf(obj); | |
var obj = Object.create({}); // creates an empty object and is equivalent to obj = {} or obj = Object.create(Object.prototype) | |
var obj1 = { | |
foo : 1, | |
bar : function() { | |
return 'Bar method called'; | |
} | |
}; | |
var obj3 = Object.create(obj1, { |
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
/* | |
Object.create(); | |
creates a new object with the specified prototype object and properties | |
object.create(proto[, propertiesObject]); | |
*/ | |
var obj = Object.create({}); // creates an empty object and is equivalent to obj = {} or obj = Object.create(Object.prototype) | |
var obj1 = { | |
foo : 1, |
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
// this would not work since unnamed functions could not be passed and then called again inside of themselves | |
[1,2,3,4,5].map(function (n) { | |
return !(n > 1) ? 1 : /* what goes here? */ (n - 1) * n; | |
}); | |
// arguments.callee was added so you could do the following | |
[1,2,3,4,5].map(function (n) { | |
return !(n > 1) ? 1 : arguments.callee(n - 1) * n; | |
}); |
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
// the following will all throw errors | |
eval = true; | |
arguments++; | |
++eval; | |
var eval; | |
function arguments(); | |
function eval(); |
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 foo = true; | |
var evalFoo = eval("'use strict'; var foo = false;"); | |
assert( foo === true ); | |
assert ( evalFoo === false ); |