模仿JQUERY写框架类
var siren=window.siren=window.$=function(selector){
          return  new siren.fn.init(selector);
}
为了让我们生成的对象能够调用在prototype里定义出来的方法, 我们需要用原型的方式(把siren当作是一个类)给siren添加一些方法
siren.fn=siren.prototype={
//构造函数应该返回一个实例
    init:function(selector){
        if(selector==null){
            return this;
        }
        this[0]= document.getElementById(selector);
        this.length=1;
        return this
        //return this;
    },
    hello:function(){
        alert(this[0].value);    
    },
    a:function(){
        alert("测试");
    },
    b:function(){
        this.a();    
    }
    
    
}
初始化实例对象
siren.fn.init.prototype = siren.fn;
//页面调用
<input id="siren" value="11111111111" />
$("siren").hello();
                    
                
                
            
        
浙公网安备 33010602011771号