Build js function within jQuery SDK
i've created a new js function like this
Object.prototype.testFn = function(){
s=this;
alert(s);
}
a='word';
a.testFn();
i'ts worki开发者_运维问答ng as well, but, when i use jQuery sdk, then i call jQuery live, my testFn function is called repeatedly. and sometimes, the whole script is not working...
As said in my comment, extending Object.prototype
is a bad idea. It most likely will break other libraries.
There is no special way to define functions when you are using jQuery. It is simply:
function myFunction(obj) {
// manipulate obj
}
But as you mention jQuery, mayby you want to create a plugin, the basic structure is:
jQuery.fn.myPlugin = function() {
// Do your awesome plugin stuff here
};
You have to extend jQuery.fn
.
How to create a plugin is very well explained in the Plugins/Authoring tutorial.
精彩评论