What are the pros & cons of these kinds of plugins? [closed]
What are the advantages and disadvantages of each one:
$.fn.hello = function() {
$(this).append('<div id="hello">Hello world</div>');
$(this).delegate('#hello', 'click', function(){
alert("Hello you clicker");
});
}
$(document).ready(function(){
$('body'开发者_如何转开发).createHello();
});
Or:
$.hello= function() {
$('body').append('<div id="hello">Hello world</div>');
$('body').delegate('#hello', 'click', function(){
alert("Hello you clicker");
});
}
$(document).ready(function(){
$.createHello();
});
?
The main advantage of that first is that you can use $(this)
, which you can't use in the second one, so you would have to change it everytime you would want to place it in different location
精彩评论