Saturday, 26 August 2017

Javascript OOP and Inheritance Technique







I'm not good at English. Please understand




When my friends have javascript oop implement



function Item (a, b, c) {
    var _a = a, _b = b, _c = c;

    return {
        init: function () {
            ...
        },

        start: function () {
            ....
        }
    }
}
var item = new Item();
item.init();
item.start();



But I would like to know the following.



function Item (a, b, c) {
    this.a = a, this.b = b, this.c = c;
}

Item.prototype.init = function () {...}
Item.prototype.start = function () {...}
var item = new Item();
item.init();

item.start();


Which do you think you?

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...