首页 > Web开发 > 详细

$().css() 设计的原理

时间:2015-08-01 12:50:15      阅读:182      评论:0      收藏:0      [点我收藏+]

普通的面向对象是这样的

 1 function test(){};
 2     test.prototype.init = function(){
 3     alert(‘初始化成功‘);
 4 }
 5     test.prototype.css = function(){
 6     alert(‘css调用也成功‘);
 7 }
 8     var ot1 = new test();
 9     ot1.init();
10     ot1.css();

jq则是直接调用,省去了new操作符,jQuery().css(); jQuery.init(); 这种设计模式应该怎样实现?

function jQuery(){

  return new jQuery.prototype.init();

}

jQuery.prototype.init = function(){};

jQuery.prototype.css = function(){ alert(‘调用成功!‘) };

jQuery.prototype.init = jQuery.prototype;

jQuery().css();

 

$().css() 设计的原理

原文:http://www.cnblogs.com/fuxiang-yang/p/4693904.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!