代码改变世界

jQuery,js如何扩展自定义方法

2019-02-21 15:23  改吧  阅读(1626)  评论(0编辑  收藏  举报
(jQuery.fn.myMethod=function () {
       alert('myMethod');
})
(function ($) {
        $.fn.extend({
             myMethod : function () {
                  alert('myMethod');
             }
        })
})(jQuery)

 

js String扩展方法

String.prototype.repalceA=function(){

   return this.replace(/a/g,'A')
}

'asdasdasd'.repalceA()
"AsdAsdAsd"