Java Reference
In-Depth Information
Superhuman.init = function(name, realName){ = name;
this.realName = realName;
this.init = undefined; // this line removes the init
function, so
it can only be called once
return this;
Now a new object can easily be created and initialized:
batman = Object.create(Superhuman);
batman.init("Batman","Bruce Wayne");;
<< "Batman"
<< "Bruce Wayne"
A new object can also be created and initialized in a single line using chaining (a technique
that will be explained in more detail later in the chapter):
aquaman = Object.create(Superhuman).init("Aquaman",
"Arthur Curry");
<< "arms": 2, "change": function () {
return this.realName + " goes into a phone box and
comes out as
" +;
}, "init": undefined, "legs": 2, "name": "Aquaman",
"Arthur Curry", "walk": function () {
console.log("Walking"); }}
Object Prototype Chain
Creating objects from objects will create a prototype chain.
Search WWH ::

Custom Search