I want to achieve a extend method on a constructor function, and use it to initialize an instance, like:
var view_instance = View.extend()
so I tried this:
define(function (require, exports, module) {
function View(size, color) {
this.size = size;
this.color = color;
};
View.prototype = {
show: function () {
console.log("This is view show");
}
}
View.extend = function (props) {
var tmp = new this("12", "red");
console.log(this);
console.log(tmp instanceof this) //true
console.log(tmp.prototype); //undefined!
return tmp
}
return View;
})
in the above extend
method, I initialize an instance through new this()
, but I can't log its prototype, and I check the this
is right.
So what's wrong with my code? Why the prototype disappear? How can I do it right?