通过构造函数创建的对象的原型指向构造函数的prototype属性
2016-05-17 20:38
423 查看
<html> <script> function Range(from,to){ this.from = from; this.to = to; } Range.prototype = { includes:function(x){return x>=this.from && x<=this.to;}, forearch:function(){for(var i = 0;i<=5;i++) console.log(i);} } var range = new Range(1,5); console.log(range.includes(3)); range.forearch(); console.log(range.from); //在调用构造函数之前就已经创建了新对象,通过this关键字可以获得这个新的对象。Range()函数只不过是初始化 //this而已。 //对Range()构造函数的调用会自动使用Range.prototype作为Range对象的原型 </script> </html>
相关文章推荐
- appache ab测试高并发
- 数据库——范式
- 网页设计代码总结-----布局(1)
- 多态和友元
- 汇总一些本人在开发中比较常用的开源库
- android视频播放
- 51nod 1189 阶乘分数(分解质因数)
- centos6.6下openoffice安装过程
- JDK7的Comparison method violates its general contract异常
- Java面向对象之接口
- hdu 3339(最短路+01背包)
- C++课程 second work _1025
- Java第八天听课总结--jar 包的使用(1)
- [置顶] 作品展示
- iOS - 报错 The dependency `xxx` is not used in any concrete target
- 选择排序之--简单选择排序,堆排序
- 计算机视觉测试数据集 dataset
- 在线编程--小范围排序
- Learning Kalman filter
- 转:windows下定时执行备份数据库