码迷,mamicode.com
首页 > 其他好文 > 详细

简化对象extend拓展

时间:2014-12-23 17:04:45      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

发现对对象继承或拷贝的时候,总是要$点来点去好麻烦,我的解决办法如下:

(function(){

  Object.prototype.extend = function(o){
    $.extend(true,this,o||{});
  };


  Function.prototype.extend = function(o){
    $.extend(true,this,o||{});
  };
})()

使用:

var a = new Object();
a.extend({info:‘yeah!‘});

var func = function(){};
var f = new func();
f.extend({info:‘yeah!‘});

结果:

a:
  Object {info: "yeah!", extend: function}
f:
  func {info: "yeah!", extend: function}

新手,如有错误,请指正!

简化对象extend拓展

标签:

原文地址:http://www.cnblogs.com/jyjin/p/4180379.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!