读书人

Prototype.js的对象的创办和扩展

发布时间: 2012-10-29 10:03:53 作者: rapoo

Prototype.js的对象的创建和扩展

     var LazyLoad = Class.create({            initialize:function(elements,callback){                this.elem = elements;                this.cb = callback;                this.show();            },            show : function(){                this.cb(this.elem);            }        });        var lz = new LazyLoad('abc',function(elem){            alert(elem);        });        //对object的prototype进行extend,参数二使用Module Pattern ^_^        Object.extend(LazyLoad.prototype,(function(){            function display(){                alert(this.elem);            }            return {                display:display,                dd:display//实现别名的功能^_^            }        })());        var lz2 = new LazyLoad('cbd',function(elem){            alert(elem);        });        lz2.display();        lz2.dd();

读书人网 >JavaScript

热点推荐