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() );
  • 相关阅读:
    进程调度算法
    操作系统文件管理
    25 个精美的手机网站模板
    WEB和APP谁是互联网未来
    网站设计趋势
    百度搜索引擎中的快照及快照更新机制
    JS实现信息的显示和隐藏
    虚拟主机单线、双线、多线的区别
    Types of Entity in Entity Framework:
    DBContext
  • 原文地址:https://www.cnblogs.com/branches/p/4870011.html
Copyright © 2011-2022 走看看