附加原型链
var obj = {} var proxy = new Proxy(obj,{ get: function(target, property) { if (property === "time") { return 36 } return 35; } }); console.log(proxy.time) console.log(proxy.name) obj.title = "title is title" console.log(obj.title) console.log(proxy.title) console.dir(proxy) var obj2 = { proxy: new Proxy(this,{ get: function(target, property) { console.log(this) if (property === "time") { return 37 } return 38; } }) } console.log(obj2.proxy.time) console.log(Object.getOwnPropertyDescriptor({ a: "aa", b: "bb" }, "b")) console.log(NaN === NaN) console.log(+0 === -0) Object.is(+0, -0) console.dir(Object.assign(1)) class Point { constructor(x, y) { Object.assign(this, { x: y, y: x }); } } console.dir(new Point(1,2)) console.log(Object(2)) const target = { a: 1, b: 2 }; const source = { b: 4, c: 5, d: ()=>{ console.log("ddddd") } }; const returnedTarget = Object.assign(target, source); console.log(returnedTarget, returnedTarget.d()) console.dir([2, 1, 3, 4]) console.dir({}) /** *** Object.appendChain(@object, @prototype) * * Appends the first non-native prototype of a chain to a new prototype. * Returns @object (if it was a primitive value it will transformed into an object). * *** Object.appendChain(@object [, "@arg_name_1", "@arg_name_2", "@arg_name_3", "..."], "@function_body") *** Object.appendChain(@object [, "@arg_name_1, @arg_name_2, @arg_name_3, ..."], "@function_body") * * Appends the first non-native prototype of a chain to the native Function.prototype object, then appends a * new Function(["@arg"(s)], "@function_body") to that chain. * Returns the function. * **/ Object.appendChain = function(oChain, oProto) { if (arguments.length < 2) { throw new TypeError('Object.appendChain - Not enough arguments'); } if (typeof oProto === 'number' || typeof oProto === 'boolean') { throw new TypeError('second argument to Object.appendChain must be an object or a string'); } var oNewProto = oProto, oReturn, o2nd, oLast; oReturn = o2nd = oLast = oChain instanceof this ? oChain : new oChain.constructor(oChain); for (var o1st = this.getPrototypeOf(o2nd); o1st !== Object.prototype && o1st !== Function.prototype; o1st = this.getPrototypeOf(o2nd)) { o2nd = o1st; } if (oProto.constructor === String) { oNewProto = Function.prototype; oReturn = Function.apply(null, Array.prototype.slice.call(arguments, 1)); this.setPrototypeOf(oReturn, oLast); } this.setPrototypeOf(o2nd, oNewProto); return oReturn; } function Symbol() { this.isSymbol = 'yes'; } var nPrime = 27; console.log(nPrime.isSymbol); console.log(typeof nPrime); // 'number' var oPrime = Object.appendChain(nPrime, new Symbol()); console.log(oPrime, nPrime); // '17' console.log(oPrime.isSymbol, nPrime.isSymbol); // 'yes' console.log(typeof oPrime, typeof nPrime); // 'object' function Mammal() { this.isMammal = 'yes'; } function MammalSpecies(sMammalSpecies) { this.species = sMammalSpecies; } MammalSpecies.prototype = new Mammal(); MammalSpecies.prototype.constructor = MammalSpecies; var oCat = new MammalSpecies('Felis'); console.log(oCat.isMammal); // 'yes' function Animal() { this.breathing = 'yes'; } var cCat = Object.appendChain(oCat, new Animal()); console.log(cCat.breathing,oCat.breathing); // 'yes'