$.extend({},旧的,新的);合并对象,后面的覆盖前面的
$.extend({},旧的,新的);合并对象,后面的覆盖前面的;
<script> $(function(){ int={ a:1, b:function(){console.log('2');} }; oldint={ a:'aaa', b:function(){console.log('bbb')}, c:'c', d:function(){console.log('ddd')} }; currentint=$.extend({},oldint,int); console.log(currentint); }) </script>
2、一个js 类拓展
$(function(){ $.fn.cityLinkage = function () { cityObj(this); } var cityObj=function(el){ var $el=$(el), testobj={}; var a={ bindclick:function(){ $el.on('click',function () { console.log($el); console.log(b.testb()); }); } } var b={ testb:function(){ return '111'; } } a.bindclick() } //用fnextend是为了 让this指向调用的对象 $("#Addr2").cityLinkage(); })