Js custom plug-in encapsulation

what is the difference between the following two prototypes of inherited development when learning about plug-in encapsulation?

function Dialog () {}

Dialog.prototype.fun1 = function () {
console.log ("fun1");
}

Dialog.prototype.fun2 = function () {
console.log ("fun2");
}

< hr >

Dialog.prototype = {

constructor: this,
fun1:function () {

console.log("fun1");   

},
fun2:function () {

console.log("fun2");   

}
}

what result do you expect? What is the error message actually seen?

Nov.14,2021

the first is to add something to the existing chain, and the second is to point to another chain
in addition, your this what the hell is


has the same effect, but the second part will rewrite the prototype chain. If you don't point constructor back to the current one, then constructor points to object, not the function you defined.


Is that the question you want to ask

?
when implementing inheritance through a prototype chain, you cannot use object literals to create a prototype method, as this will override the prototype chain

function SuperType() {
    this.property = true;
}

SuperType.prototype.getSuperValue = function () {
    return this.property;
}

function SubType() {
    this.subproperty = false;
}

//SuperType 
SubType.prototype = new SuperType();

// 
SubType.prototype = {
    getSubValue: function () {
        return this.subproperty;
    },
    someOtherMethod: function () {
        return false;
    }

}
var instance = new SubType();
alert(instance.getSuperValue()); //error
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b404a8-4f166.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b404a8-4f166.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?