一圖已然說明問題
附上代碼
js中prototype,
// 本地對象 native object
// 內置對象 native object
// 宿主對象 host object
// 自定義對象 user-defined object
// 自有屬性 own property
// 繼承屬性 inherited propertyconsole.log("sdfsdf");function inherit(p) {if(p == null) //throw TypeError();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; // 將其原型屬性設置為preturn new f(); // 使用f()創建p的繼承對象
}function xzm() {this.x = 3;this.y = 4;
}var pInher = new xzm();var pro0 = inherit(pInher);var pro1 = Object.create(pInher);
var pro2 = new Object(pInher);
附上截圖
prototype、
Tony朱 ? ? ?對__proto__和prototype的理解
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态