You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const_create=(proto,propertiesObject,isNeedSupportSecondParam=false)=>{//参数校验if(typeofproto!=="object"&&proto!==null)thrownewError("the first param must be an object or null");if(isNeedSupportSecondParam&&propertiesObject===null){throw"TypeError";}functionF(){}F.prototype=proto;constobj=newF();if(proto===null){obj.__proto__=proto;}if(isNeedSupportSecondParam&&propertiesObject!==null){Object.defineProperties(obj,propertiesObject);}returnobj;};
Object.mycreate=function(proto,propertiesObject){if(typeof(proto)!=='object'&&proto!==null)thrownewError("the first param must be an object or null");functionFn(){}Fn.prototype=protoif(propertiesObject)Object.defineProperties(obj,propertiesObject);returnnewFn}
constcreate=(prop,props)=>{if(!['object','function'].includes(typeofprop)){thrownewTypeError(`Object prototype my only be an Object or null: ${prop}`)}constCtor=function(){}// 创建构造函数Ctor.prototype=prop// 赋值原型constobj=newCtor()// 创建实例if(props)Object.defineProperties(obj,props)// 支持第二个参数if(prop===null)obj.__proto__=null// 支持空原型returnobj}
The text was updated successfully, but these errors were encountered:
Object.create() 方法创建一个新对象,使用现有的对象来提供新创建的对象的
__proto__
Object.create(proto,[propertiesObject])
proto:新创建对象的原型对象。
propertiesObject:可选。需要传入一个对象,该对象的属性类型参照Object.defineProperties()的第二个参数。如果该参数被指定且不为 undefined,该传入对象的自有可枚举属性(即其自身定义的属性,而不是其原型链上的枚举属性)将为新创建的对象添加指定的属性值和对应的属性描述符。
The text was updated successfully, but these errors were encountered: