Object-Oriented JavaScript - Third Edition by Ved Antani & Stoyan Stefanov

Object-Oriented JavaScript - Third Edition by Ved Antani & Stoyan Stefanov

Author:Ved Antani & Stoyan Stefanov
Language: eng
Format: mobi
Publisher: Packt Publishing
Published: 2017-01-11T23:00:00+00:00


Let's test this by creating three objects-shape, twoDee, and a third, unnamed object. Then, creating a triangle object means calling multi() and passing all three objects:

var shape = {

name: 'Shape',

toString: function () {

return this.name;

}

};

var twoDee = {

name: '2D shape',

dimensions: 2

};

var triangle = multi(shape, twoDee, {

name: 'Triangle',

getArea: function () {

return this.side * this.height / 2;

},

side: 5,

height: 10

});

Does this work? Let's see. The getArea() method should be an own property, dimensions should come from twoDee, and toString() should come from shape:

>triangle.getArea();

25

>triangle.dimensions;

2

>triangle.toString();

"Triangle"



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.