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

普通的面向对象是这样的

 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();
原文地址:https://www.cnblogs.com/fuxiang-yang/p/4693904.html