zoukankan      html  css  js  c++  java
  • jQuery.core_01

    自己读jQuery代码有些日子了,一直感觉没领悟到什么,一直也没有写些东东,来记录下自己的感悟,看到各位大神的blogs,就一直没勇气去写下来,纠结再三,觉得还是有必要写下点东西,不论幼稚,肤浅,只求自己有点长进...

     先看一下jQuery实例:

    1 jQuery = function( selector, context ){
    2   return new jQuery.fn.init( selector, context );  
    3 }
    4 
    5 vae init = jQuery.fn.init = function( selector, context ){
    6 
    7 }

    看到没,其实jQuery的构造函数是 init 

    那么,jQuery实例就现在来看,是无法访问到jQuery.prototype的method,property.

    再看一下,神奇的一段代码:

    init.prototype = jQuery.prototype

    这是一段测试编码:

    var init = function( name, age ){
        this.name = name;
        this.age = age;
    }
    
    var jQuery = function( name, age ){
        return new init( name, age );
    };
    
    jQuery.prototype  = {
        getName: function(){
            return this.name;
        },
        
        getAge: function(){
            return this.age;
        },
        
        age: 19
    };
    
    init.prototype = jQuery.prototype;
    
    var j = jQuery( 'branches',18);
    console.log( j.age );
    console.log( j.getName() );
    
    jQuery.s = "static_";
    
    jQuery.getName = function(){
        return this.s;
    };
    
    console.log( jQuery.getName() );
  • 相关阅读:
    POJ 3744:Scout YYF I 概率DP+特征方程+快速幂
    浏览器实现颜色渐变效果(兼容)
    css透明(支持各浏览器)
    sql server密钥
    DDL(Oracle)
    DML(Oralce)
    SQL(Oracle)
    Reflect
    Exception
    XML语法
  • 原文地址:https://www.cnblogs.com/branches/p/4870011.html
Copyright © 2011-2022 走看看