JS中prototype的实例
来源:互联网 发布:都玩网络怎么样 编辑:程序博客网 时间:2024/04/25 19:19
1、可以在类型上使用proptotype来为类型添加行为。这些行为只能在类型的实例上体现
JS中允许的类型有Array, Boolean, Date, Enumerator, Error, Function, Number, Object, RegExp, String
JS中允许的类型有Array, Boolean, Date, Enumerator, Error, Function, Number, Object, RegExp, String
Object.prototype.Property = 1;Object.prototype.Method = function (){ alert(1);} var obj = new Object();alert(obj.Property);obj.Method();
2、在实例上不能使用prototype,否则发生编译错误
var obj = new Object(); obj.prototype.Property = 1; //Error//Errorobj.prototype.Method = function(){ alert(1);}
3、可以为类型定义“静态”的属性和方法,直接在类型上调用即可
Object.Property = 1;Object.Method = function(){ alert(1);}alert(Object.Property);Object.Method();
4、可以在外部使用prototype为自定义的类型添加属性和方法
function Aclass(){this.Property = 1;this.Method = function(){ alert(1);}}Aclass.prototype.Property2 = 2;Aclass.prototype.Method2 = function{ alert(2);}var obj = new Aclass();alert(obj.Property2);obj.Method2();
参考资料: JS中prototype http://www.studyofnet.com/news/556.html
0 0
- JS中prototype的实例
- js中对prototype对象继承的一个实例
- JS中prototype的用法
- js中prototype的笔记
- js中prototype的陷阱
- js中prototype的理解
- prototype.js开发实例
- prototype.js开发实例
- js中prototype用法实例(为数组添加contains方法)
- js中prototype的一个小例子
- js中prototype的继承和扩展
- 对js中new、prototype的理解
- JS中 prototype 关键字的使用
- 关于js中prototype的理解
- JS中prototype属性的理解
- js中prototype的理解摘录
- 关于JS中prototype的理解
- JS中__proto__与prototype的关系
- Android.mk for your own module [M
- EasyBCD在windows7基础上安装Ubuntu 14.04双系统详
- trie tree
- Memory barrier——WiKi
- [LeetCode] Valid Sudoku Partition List
- JS中prototype的实例
- mysql中存不进去json_encode格式的数据
- 第十八章_SSL证书
- 数字图像处理,读懂频域处理的“傅里叶变换”
- 网页浏览器发展方向总结
- 上传第三方jar包到nexus
- PHP 5.6.0发布 use关键字可导入函数与常量
- poj 2533 Longest Ordered Subsequence
- 第一章-任务1:Linux内核的重新编译,安装,重启