function Animal(type) {
this.type = type
}
Animal.prototype.say = function() {
console.log('say')
}
function myNew(fn, ...args)
{ let obj = Object.create(fn.prototype);
let res = fn.call(obj, ...args);
if (res && (typeof res === "object" || typeof res === "function"))
{ return res; }
return obj;
}
function newMy(){
let Constructor = [].shift.call(arguments)
let obj = {}
obj.__proto__ = Constructor.prototype
let r = Constructor.apply(obj,arguments)
return r instanceof Object ? r : obj
}
let animal = newMy(Animal,'爬行动物')
animal.say()
