to implement convenient object inheritance, the code is as follows:
let obj = { //objjson
"a": 1,
"b": 2,
"d": {
"d": 4
}
}
let obj1 = newObj(obj); //obj1obj
obj1.a = 3; //obj1obj
obj.c = 4; //objobj1
obj1.d.d = 6; //obj1obj,obj.d.d=4
obj.d.d = 5; //obj1.d.d=6,"obj1.d.d = 6;"obj1.d.d=5
newObj () is the solution to this question I hope the boss can give a solution or idea
tried ideas:
(abandon) original prototype inheritance: the attribute name and length of obj are unknown, so it is too troublesome to write. It may be that I am not completely independent of
(failure) obj1 deep cloning obj:obj1 and obj, and obj1 cannot be updated with obj;
(failure) obj1 is cloned deeply first and then opens a field to directly reference the part of the public address referenced by obj:. Obj1 will affect obj