我有一个对象/函数/闭包(我认为这三个都是?),我需要将它的单独实例应用于页面上的多个元素。
var NS = NS || {};
NS.PLAJAX = function(){
var pub = {};
var self = this;
pub.Init = function(FormRef){
// do stuff
};
self.aPrivateFunction = function(){
// do stuff
}
return pub;
}();
// Apply a *copy* to each element with the given class
$(function(){
$('.el-form-wrapper').each(function(index, Element){
// Attempt #1
NS.PLAJAX.Init(Element); // Doesn't make copies!
//OR, Attempt #2
var Newbie = new NS.PLAJAX(); // Throws a "not a constructor" error
Newbie.Init(Element);
});
});
如何在每个元素上获取此闭包/对象的新实例?