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 products = { | |
"widget": 400, | |
"gear": 80, | |
"crank": 375, | |
"lever": 870, | |
}; | |
var otherProducts = Object.create(products); | |
otherProducts["wheel"] = 210; |
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 products = { | |
"widget": 400, | |
"gear": 80, | |
"crank": 375, | |
"lever": 870, | |
}; | |
var otherProducts = Object.create(products); | |
otherProducts["wheel"] = 210; |
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
// prototypes0.js | |
var obj = {}; | |
console.log(obj.toString()); | |
// Logs: [object Object] |
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
// prototypes1.js | |
var obj = {}; | |
console.log(Object.getPrototypeOf(obj)); | |
/* Logs: | |
{ | |
constructor: ƒ Object(), |
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
// prototypes1a.js | |
var obj = {}; | |
obj.toString = function() { | |
console.log("I'm an object!"); | |
}; | |
obj.toString(); | |
// Logs: "I'm an object!" |
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
// prototypes2.js | |
var House = { | |
ringDoorbell: function() { | |
console.log("ding dong!"); | |
}, | |
describe: function() { | |
console.log(this.owner + "'s house has " + this.rooms + " rooms."); | |
} |
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
// prototypes3.js | |
var House = { | |
ringDoorbell: function() { | |
console.log("ding dong!"); | |
}, | |
describe: function() { | |
console.log(this.owner + "'s house has " + this.rooms + " rooms."); | |
} |
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
// prototypes4.js | |
var House = { | |
ringDoorbell: function() { | |
console.log("ding dong!"); | |
}, | |
describe: function() { | |
console.log(this.owner + "'s house has " + this.rooms + " rooms."); | |
} |
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
// prototypes5.js | |
function crawlPrototypeChain(obj) { | |
console.log("-----------------"); | |
console.log("Object: ", obj); | |
console.log("Own Properties: ", Object.getOwnPropertyNames(obj)); | |
var objPrototype = Object.getPrototypeOf(obj); | |
if (objPrototype) { | |
crawlPrototypeChain(objPrototype); |
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
function Robot(name, job) { | |
this.name = name; | |
this.job = job; | |
this.introduce = function() { | |
console.log("Hi! I'm " + this.name + ". My job is " + this.job + "."); | |
}; | |
} | |
function AI(name, job, intelligenceLevel) { |