Home > Article > Web Front-end > How to prevent library functions from being accidentally modified incorrectly
When a function reads an inherited object, it actually reads the inherited value. If you assign values to the properties of an inherited object, these properties will only affect the inherited object itself, not the original object
//inherit()返回了一个继承自原型对象p的属性的新对象 //这里使用ECMAScript 5中的Object.create()函数(如果可用) //如果不可用,则使用其它方法 function inherit(p) { if (p == null) throw TypeError(); //p是一个对象,但不能是null if (Object.create) //如果Object.create()存在 return Object.create(p); //直接使用 var t = typeof p; //否则进一步检验 if (t !== "object" && t !== "function") throw TypeError(); function f() { }; //定义一个空构造函数 f.prototype = p; //将其原型属性设置未p return new f(); //使用f()创建p的继承对象 }
The above is the detailed content of How to prevent library functions from being accidentally modified incorrectly. For more information, please follow other related articles on the PHP Chinese website!