为情所困2017-06-12 09:31:41
將建構子指向本身,否則預設指向Object
var Plugin = function(){}
Plugin.prototype = {
sayHello:function(){
console.log("hello")
}
}
var p = new Plugin()
console.log(p.constructor === Object) //true
如果加上constructor
var Plugin = function(){}
Plugin.prototype = {
constructor: Plugin,
sayHello:function(){
console.log("hello")
}
}
var p = new Plugin()
console.log(p.constructor === Plugin) //true