JavaScript子类用Object.getPrototypeOf去调用父类方法

摘要: 每个function有个prototype属性,称为原型。每个对象也有个原型,Firefox/Safari/Chrome/Opera 中可以通过__proto__来访问,IE6/7/8中没有提供相关接口。function Person(){ this.method1 = function(){}}Person.prototype.method2 = function(){}function Man(){}Man.prototype = new Person();Man.prototype.m1 = function(){}Man.prototype.m2 = function(){}var m 阅读全文
posted @ 2011-03-23 10:01 snandy 阅读(10615) 评论(6) 推荐(9) 编辑

使用隐藏的new来创建对象

摘要: jQuery中发现的,jQuery.Event类。估计作者是为了减少代码量。定义一个类,但不用new关键字去创建该类对象,而使用方法调用()方式去创建该对象。很多时候我们是这样写类,然后使用new创建对象的。function Person(name,age){ this.name=name; this.age=age;}Person.prototype={ setName : function(n){this.name=n;}, getName : function(){return this.name;}}var p = new Person('jack',25);改... 阅读全文
posted @ 2011-03-23 08:47 snandy 阅读(3264) 评论(13) 推荐(2) 编辑
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示