每一个对象都有与之相关的 prototype ,class 、extensible attribute 。
prototype
参考链接:https://msdn.microsoft.com/zh-cn/library/kb6te8d3(v=vs.94).aspx
isPrototypeOf 方法 (Object) (JavaScript)
确定一个对象是否存在于另一个对象的原型链中。
如果 object 的原型链中具有 prototype,则 isPrototypeOf 方法返回 true。原型链用于在同一个对象类型的不同实例之间共享功能。当 object 不是对象或当 prototype 没有出现在 object 的原型链中时,isPrototypeOf 方法返回 false。
<!DOCTYPE html> <lang ="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script type="text/javascript"> function Pasta(grain, width) { this.grain = grain; this.width = width; } // Create an object from the pasta constructor. var spaghetti = new Pasta("wheat", 0.2); // Obtain the prototype from the object. var proto = Object.getPrototypeOf(spaghetti); // Add a property to the prototype and validate that // the original object has the property. proto.foodgroup = "carbohydrates"; document.write(spaghetti.foodgroup + " "); // Verify that the prototype obtained from the object // is the same as the prototype of the constructor. var result = (proto === Pasta.prototype); document.write(result + " "); // Verify that prototype obtained from the object // is a prototype of the original object. var result = proto.isPrototypeOf(spaghetti); document.write(result); </script> <script type="text/javascript"> var p = {x:1}; var o = Object.create(p); p.isPrototypeOf(o) Object.prototype.isPrototypeOf(o) //p 继承自 Object prototype </script> </head> <body> </body> </html>
类属性: