Constructor appends a method in the specified object,

a ={
  x:function(){console.log(1)}
}
function B(){
 this.y = function(){}
}

think var b = new B ();

b = {
 x:...,
 y:....
}

how to implement

Mar.23,2021

Add a step before

new to attach the method in object a to the prototype of B.

Object.keys(a).forEach(function(v) {
    B.prototype[v] = a[v]
})
var b = new B()

you can also copy the methods in object a directly into b after new (of course, this may overwrite the methods in the constructor

var b = new B()
Object.keys(a).forEach(function(v) {
    b[v] = a[v]
})

if you just want to simply put a.x into b, the simplest thing is b.x = a.x. Since you didn't mention the specific needs, you might as well refer to the boss upstairs.

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-1b31c1d-2bdd2.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-1b31c1d-2bdd2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?