jQuery自定义类封装:


jQuery自定义类封装:

 

(function ($) {

    $.DragField = function (arg) {

        var name = "你好";     //这个是私有变量,外部无法访问

        this.testFun = function () {     //this.testFun方法,加上了this,就是公有方法了,外部可以访问。

            alert(arg.title + "," + name);

        };

    };

})(jQuery);

 

使用方法:

var a = new $.DragField({ title: "Hi" });

var b = new $.DragField({ title: "Hello" });

a.testFun();

b.testFun();


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM