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();