关于prototype的一点疑惑 javascriptprototype 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 那你想让this指向哪阿?function TestClass(){ this.property = true; } TestClass.prototype.getFatherValue = function(){ return this.property; }; var test = new TestClass(); window.alert(test.constructor.prototype.getFatherValue.call(test)); this不是指向TestClass吗?上面的getValue()方法写错了,应该是getFatherValue()。prototype是test的原型,getFatherValue()在prototype中,按道理是可以通过test.prototype.getFatherValue()来访问的。 举个简单的例子:TestClass是你师父,getFatherValue是你师父赚钱的能力。你师父教会你赚钱的能力 test = new TestClass(); 但你不能直接去拿你师父的钱:test.prototype.getFaterValue,你得自己去拿钱。test.getFatherValue。而且根据js的规则,你想再找个徒弟,那需要经过多次的处理。一般叫继承。这是一条js语法规则,这样做的目的,就是为了编程完全不能让实例化的对象test直接去改变父类的getFatherValue的方法。这是我个人的理解,更管方的参考上面的图,或javascript高级程序设计 第三版 148页 理解原型对象。 谢谢大家的指教,根据大家的答案和参考javascript高级程序设计,总结如下:1.prototype属性是构造函数(TestClass())的属性,实例test没有prototype属性。2.实例有一个指针[[prototype]]指向构造函数的prototype。3.可以通过两种方法访问构造函数的prototype:通过test的proto属性和Object.getPrototypeOf(test) 字符串替代 哪位大哥知道options.unshift()方法怎么用啊,请赐教啊,在线等 不按ctrl键,点击鼠标左键就实现select控件项目的多选和反选? 这段代码怎么样才能通过W3C标准验证呢 庆祝离职,自由万岁! 紧急求助,已经找不到原文件的jsp网站如何运行,work目录下有已经编译的完整的servlet 怎样控制iframe中的内容(iframe跨站) 如何模拟"SHITF"+"TAB",谢谢啦 为什么实现不了JS拖拽的效果 谁电脑上有J2SE,帮个小忙吧! 鼠标移动到div上时页面滚动无效,滚轮只用于该div,移出div时滚轮只用于body. 这段正则如何写
function TestClass(){
this.property = true;
}
TestClass.prototype.getFatherValue = function(){
return this.property;
};
var test = new TestClass();
window.alert(test.constructor.prototype.getFatherValue.call(test));
举个简单的例子:TestClass是你师父,getFatherValue是你师父赚钱的能力。
你师父教会你赚钱的能力 test = new TestClass(); 但你不能直接去拿你师父的钱:test.prototype.getFaterValue,你得自己去拿钱。test.getFatherValue。而且根据js的规则,你想再找个徒弟,那需要经过多次的处理。一般叫继承。
这是一条js语法规则,这样做的目的,就是为了编程完全不能让实例化的对象test直接去改变父类的getFatherValue的方法。这是我个人的理解,更管方的参考上面的图,或javascript高级程序设计 第三版 148页 理解原型对象。
1.prototype属性是构造函数(TestClass())的属性,实例test没有prototype属性。
2.实例有一个指针[[prototype]]指向构造函数的prototype。
3.可以通过两种方法访问构造函数的prototype:通过test的proto属性和Object.getPrototypeOf(test)