如何将现有的原型函数更改为jquery?
即
MainWindow = function()
{
this.activeUser = "";
this.name = "";
}
调用bindAll
MainWindow.prototype.bindAll = function() {
答案 0 :(得分:2)
你可以写一个jQuery插件......
(function($) {
$.fn.mainWindow = function() {
...
}
})(jQuery);
然后像:
一样使用它$('#thingy').mainWindow();
答案 1 :(得分:1)
常用方法是在jQuery的上下文中使用匿名函数,例如:
// anonymous function that is executed within the jQuery context
// to preserve reference in case of $.noConflict
(function($){
// $ is now short for jQuery
// $.fn is short for jQuery.prototype
// if you want $.myCustomFunction
$.extend({
myCustomFunction: function(arg){
$('#test').append($('<p>').text('myCustomFunction: '+arg));
}
});
// or if you want $('...').myCustomFunction()
$.fn.extend({
myCustomFunction: function(arg){
$.myCustomFunction(arg + ' [from selector]');
}
});
})(jQuery);