javascript - What is the use of constructor:Plugin statement in jq plug-in?
女神的闺蜜爱上我
女神的闺蜜爱上我 2017-06-12 09:29:41
0
1
747

I encountered problems in the case I referred to when learning jquery custom plug-in development.

女神的闺蜜爱上我
女神的闺蜜爱上我

reply all(1)
为情所困

Point the constructor to itself, otherwise it will point to Object by default

var Plugin = function(){}
Plugin.prototype = {
    sayHello:function(){
        console.log("hello")
    }
}
var p = new Plugin()
console.log(p.constructor === Object) //true

If you add constructor

var Plugin = function(){}
Plugin.prototype = {
    constructor: Plugin,
    sayHello:function(){
        console.log("hello")
    }
}
var p = new Plugin()
console.log(p.constructor === Plugin) //true
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template