实例详解jQuery的无new构建
jQuery的无new构建 jQuery框架的核心就是从HTML文档中匹配元素并对其执行操作、 回想一下使用 jQuery 的时候,实例化一个 jQuery 对象的方法: // 无 new 构造
$('#test').text('Test'); // 当然也可以使用 new
var test = new $('#test');
test.text('Test');
大部分人使用 jQuery 的时候都是使用第一种无 new 的构造方式,直接 $('') 进行构造,这也是 jQuery 十分便捷的一个地方。 当我们使用第一种无 new 构造方式的时候,其本质就是相当于 new jQuery(),那么在 jQuery 内部是如何实现的呢?看看: (function(window, undefined) {
var
// ...
jQuery = function(selector, context) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init(selector, context, rootjQuery);
}, jQuery.fn = jQuery.prototype = {
init: function(selector, context, rootjQuery) {
// ...
}
}
jQuery.fn.init.prototype = jQuery.fn;
})(window);
没看懂?没关系,我们一步一步分析。 函数表达式和函数声明 在ECMAScript中,创建函数的最常用的两个方法是函数表达式和函数声明,两者期间的区别是有点晕,因为ECMA规范只明确了一点:函数声明必须带有标示符(Identifier)(就是大家常说的函数名称),而函数表达式则可以省略这个标示符:
//函数声明:
function 函数名称 (参数:可选){ 函数体 }
//函数表达式:
function 函数名称(可选)(参数:可选){ 函数体 }
所以,可以看出,如果不声明函数名称,它肯定是表达式,可如果声明了函数名称的话,如何判断是函数声明还是函数表达式呢? ECMAScript是通过上下文来区分的,如果function foo(){}是作为赋值表达式的一部分的话,那它就是一个函数表达式, 如果function foo(){}被包含在一个函数体内,或者位于程序的最顶部的话,那它就是一个函数声明
function foo(){} // 声明,因为它是程序的一部分
var bar = function foo(){}; // 表达式,因为它是赋值表达式的一部分
new function bar(){}; // 表达式,因为它是new表达式
(function(){
function bar(){} // 声明,因为它是函数体的一部分
})();
还有一种函数表达式不太常见,就是被括号括住的(function foo(){}),他是表达式的原因是因为括号 ()是一个分组操作符,它的内部只能包含表达式 再来看jQuery源码:
(function(window, undefined) {
/...
})(window)
可以将上面的代码结构分成两部分:(function(){window, undefined}) 和 (window) , 第1个()是一个表达式,而这个表达式本身是一个匿名函数, 所以在这个表达式后面加(window)就表示执行这个匿名函数并传入参数window。 原型 prototype 认识一下什么是原型? 在JavaScript中,原型也是一个对象,通过原型可以实现对象的属性继承,JavaScript的对象中都包含了一个" [[Prototype]]"内部属性,这个属性所对应的就是该对象的原型。 对于"prototype"和"__proto__"这两个属性有的时候可能会弄混,"Person.prototype"和"Person.__proto__"是完全不同的。 在这里对"prototype"和"__proto__"进行简单的介绍: 1.对于所有的对象,都有__proto__属性,这个属性对应该对象的原型
2.对于函数对象,除了__proto__属性之外,还有prototype属性,当一个函数被用作构造函数来创建实例时,该函数的prototype属性值将被作为原型赋值给所有对象实例(也就是设置实例的__proto__属性) function Person(name, age){
this.name = name;
this.age = age;
}
Person.prototype.getInfo = function(){
console.log(this.name + " is " + this.age + " years old");
};
//调用
var will = new Person("Will", 28);
will.getInfo();//"Will is 28 years old"
闭包 闭包的定义: 当一个内部函数被其外部函数之外的变量引用时,就形成了一个闭包。 闭包的作用: 在了解闭包的作用之前,我们先了解一下 javascript中的GC机制: 在javascript中,如果一个对象不再被引用,那么这个对象就会被GC回收,否则这个对象一直会保存在内存中。 在上述例子中,B定义在A中,因此B依赖于A,而外部变量 c 又引用了B, 所以A间接的被 c 引用, 也就是说,A不会被GC回收,会一直保存在内存中。为了证明我们的推理,看如下例子: function A(){
var count = 0;
function B(){
count ++;
console.log(count);
}
return B;
}
var c = A();
c();//
c();//
c();//
count是A中的一个变量,它的值在B中被改变,函数B每执行一次,count的值就在原来的基础上累加1。因此,A中的count一直保存在内存中。 这就是闭包的作用,有时候我们需要一个模块中定义这样一个变量:希望这个变量一直保存在内存中但又不会“污染”全局的变量,这个时候,我们就可以用闭包来定义这个模块 在看jQuery源码: (function(window, undefined) {
var
// ...
jQuery = function(selector, context) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init(selector, context, rootjQuery);
},
jQuery.fn = jQuery.prototype = {
init: function(selector, context, rootjQuery) {
// ...
}
}
jQuery.fn.init.prototype = jQuery.fn;
})(window); 我们知道了 什么是闭包:当一个内部函数被其外部函数之外的变量引用时,就形成了一个闭包。 jQuery.fn的init 函数被jQuery 的构造函数调用了,这里形成了一个闭包。
构造函数及调用代码:
// ...
jQuery = function(selector, context) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init(selector, context, rootjQuery);
},
问题关键来了。 如何实现无new构建 JavaScript是函数式语言,函数可以实现类,类就是面向对象编程中最基本的概念 var aQuery = function(selector, context) {
//构造函数
}
aQuery.prototype = {
//原型
name:function(){},
age:function(){}
}
var a = new aQuery();
a.name(); 这是常规的使用方法,显而易见jQuery不是这样玩的 要实现这样,那么jQuery就要看成一个类,那么$()应该是返回类的实例才对 按照jQuery的抒写方式 $().ready()
$().noConflict()
要实现这样,那么jQuery就要看成一个类,那么$()应该是返回类的实例才对 所以把代码改一下: var aQuery = function(selector, context) {
return new aQuery();
}
aQuery.prototype = {
name:function(){},
age:function(){}
}
通过new aQuery(),虽然返回的是一个实例,但是也能看出很明显的问题,死循环了! 那么如何返回一个正确的实例? 在javascript中实例this只跟原型有关系 那么可以把jQuery类当作一个工厂方法来创建实例,把这个方法放到aQuery.prototye原型中 var aQuery = function(selector, context) {
return aQuery.prototype.init(selector);
}
aQuery.prototype = {
init:function(selector){
return this;
}
name:function(){},
age:function(){}
}
当执行aQuery() 返回的实例: 很明显aQuery()返回的是aQuery类的实例,那么在init中的this其实也是指向的aQuery类的实例 问题来了init的this指向的是aQuery类,如果把init函数也当作一个构造器,那么内部的this要如何处理? var aQuery = function(selector, context) {
return aQuery.prototype.init(selector);
}
aQuery.prototype = {
init: function(selector) {
this.age = 18
return this;
},
name: function() {},
age: 20
}
aQuery().age //
因为this只是指向aQuery类的,所以aQuery的age属性是可以被修改的。 这样看似没有问题,其实问题很大的 为什么是new jQuery.fn.init? 看如下代码: var aQuery = function(selector, context) {
return aQuery.prototype.init(selector);
}
aQuery.prototype = {
init: function(selector) {
if(selector=="a")
this.age = 18
return this;
},
name: function() {},
age: 20
}
aQuery("a").age //
aQuery("b").age // 当我调用 传入"a"的时候,修改age=18,及aQuery("a").age 的值为18 但是当我 传入"b"的时候 并没又修改 age的值,我也希望得到默认age的值20,但是aQuery("b").age 的值为18. 因为在 调用aQuery("a").age 的时候age被修改了。 这样的情况下就出错了,所以需要设计出独立的作用域才行。 jQuery框架分隔作用域的处理
jQuery = function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context, rootjQuery );
},
很明显通过实例init函数,每次都构建新的init实例对象,来分隔this,避免交互混淆 我们修改一下代码: var aQuery = function(selector, context) {
return new aQuery.prototype.init(selector);
}
aQuery.prototype = {
init: function(selector) {
if(selector=="a")
this.age = 18
return this;
},
name: function() {},
age: 20
}
aQuery("a").age //
aQuery("b").age //undefined
aQuery("a").name() //Uncaught TypeError: Object [object Object] has no method 'name'
又出现一个新的问题, age :undefined,
name() :抛出错误,无法找到这个方法,所以很明显new的init跟jquery类的this分离了 怎么访问jQuery类原型上的属性与方法? 做到既能隔离作用域还能使用jQuery原型对象的作用域呢,还能在返回实例中访问jQuery的原型对象实现的关键点 // Give the init function the jQuery prototype for later instantiation
jQuery.fn.init.prototype = jQuery.fn;
我们再改一下: var aQuery = function(selector, context) {
return new aQuery.prototype.init(selector);
}
aQuery.prototype = {
init: function(selector) {
if(selector=="a")
this.age = 18
return this;
},
name: function() {
return age;
},
age: 20
}
aQuery.prototype.init.prototype = aQuery.prototype;
aQuery("a").age //
aQuery("b").age //
aQuery("a").name() //
最后在看一下jQuery源码: (function(window, undefined) {
var
// ...
jQuery = function(selector, context) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init(selector, context, rootjQuery);
},
jQuery.fn = jQuery.prototype = {
init: function(selector, context, rootjQuery) {
// ...
}
}
jQuery.fn.init.prototype = jQuery.fn;
})(window);
是不是明白了? 哈哈哈~~~ 在简单说两句: 大部分人初看 jQuery.fn.init.prototype = jQuery.fn 这一句都会被卡主,很是不解。但是这句真的算是 jQuery 的绝妙之处。理解这几句很重要,分点解析一下: 1)首先要明确,使用 $('xxx') 这种实例化方式,其内部调用的是 return new jQuery.fn.init(selector, context, rootjQuery) 这一句话,也就是构造实例是交给了 jQuery.fn.init() 方法取完成。 2)将 jQuery.fn.init 的 prototype 属性设置为 jQuery.fn,那么使用 new jQuery.fn.init() 生成的对象的原型对象就是 jQuery.fn ,所以挂载到 jQuery.fn 上面的函数就相当于挂载到 jQuery.fn.init() 生成的 jQuery 对象上,所有使用 new jQuery.fn.init() 生成的对象也能够访问到 jQuery.fn 上的所有原型方法。 3)也就是实例化方法存在这么一个关系链 1.jQuery.fn.init.prototype = jQuery.fn = jQuery.prototype ;
2.new jQuery.fn.init() 相当于 new jQuery() ;
3.jQuery() 返回的是 new jQuery.fn.init(),而 var obj = new jQuery(),所以这 2 者是相当的,所以我们可以无 new 实例化 jQuery 对象。
jQuery的无new构建
jQuery框架的核心就是从HTML文档中匹配元素并对其执行操作、
回想一下使用 jQuery 的时候,实例化一个 jQuery 对象的方法:
| 1 2 3 4 5 6 | // 无 new 构造$('#test').text('Test'); // 当然也可以使用 newvartest = new$('#test');test.text('Test'); | 
大部分人使用 jQuery 的时候都是使用第一种无 new 的构造方式,直接 $('') 进行构造,这也是 jQuery 十分便捷的一个地方。
当我们使用第一种无 new 构造方式的时候,其本质就是相当于 new jQuery(),那么在 jQuery 内部是如何实现的呢?看看:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | (function(window, undefined) {  var  // ...  jQuery = function(selector, context) {    // The jQuery object is actually just the init constructor 'enhanced'    returnnewjQuery.fn.init(selector, context, rootjQuery);  },   jQuery.fn = jQuery.prototype = {    init: function(selector, context, rootjQuery) {      // ...    }  }  jQuery.fn.init.prototype = jQuery.fn;})(window); | 
没看懂?没关系,我们一步一步分析。
函数表达式和函数声明
在ECMAScript中,创建函数的最常用的两个方法是函数表达式和函数声明,两者期间的区别是有点晕,因为ECMA规范只明确了一点:函数声明必须带有标示符(Identifier)(就是大家常说的函数名称),而函数表达式则可以省略这个标示符: 
| 1 2 3 4 | //函数声明:function函数名称 (参数:可选){ 函数体 }//函数表达式:function函数名称(可选)(参数:可选){ 函数体 } | 
所以,可以看出,如果不声明函数名称,它肯定是表达式,可如果声明了函数名称的话,如何判断是函数声明还是函数表达式呢?
ECMAScript是通过上下文来区分的,如果function foo(){}是作为赋值表达式的一部分的话,那它就是一个函数表达式,
如果function foo(){}被包含在一个函数体内,或者位于程序的最顶部的话,那它就是一个函数声明。
| 1 2 3 4 5 6 | functionfoo(){} // 声明,因为它是程序的一部分varbar = functionfoo(){}; // 表达式,因为它是赋值表达式的一部分newfunctionbar(){}; // 表达式,因为它是new表达式(function(){ functionbar(){} // 声明,因为它是函数体的一部分})(); | 
还有一种函数表达式不太常见,就是被括号括住的(function foo(){}),他是表达式的原因是因为括号 ()是一个分组操作符,它的内部只能包含表达式
再来看jQuery源码:
| 1 2 3 | (function(window, undefined) {  /...})(window) | 
可以将上面的代码结构分成两部分:(function(){window, undefined}) 和 (window) ,
第1个()是一个表达式,而这个表达式本身是一个匿名函数,
所以在这个表达式后面加(window)就表示执行这个匿名函数并传入参数window。
原型 prototype
认识一下什么是原型?
在JavaScript中,原型也是一个对象,通过原型可以实现对象的属性继承,JavaScript的对象中都包含了一个" [[Prototype]]"内部属性,这个属性所对应的就是该对象的原型。
对于"prototype"和"__proto__"这两个属性有的时候可能会弄混,"Person.prototype"和"Person.__proto__"是完全不同的。
在这里对"prototype"和"__proto__"进行简单的介绍:
1.对于所有的对象,都有__proto__属性,这个属性对应该对象的原型
2.对于函数对象,除了__proto__属性之外,还有prototype属性,当一个函数被用作构造函数来创建实例时,该函数的prototype属性值将被作为原型赋值给所有对象实例(也就是设置实例的__proto__属性)
| 1 2 3 4 5 6 7 8 9 10 | functionPerson(name, age){  this.name = name;  this.age = age;}Person.prototype.getInfo = function(){  console.log(this.name + " is "+ this.age + " years old");};//调用varwill = newPerson("Will", 28);will.getInfo();//"Will is 28 years old" | 
闭包
闭包的定义:
当一个内部函数被其外部函数之外的变量引用时,就形成了一个闭包。
闭包的作用:
在了解闭包的作用之前,我们先了解一下 javascript中的GC机制:
在javascript中,如果一个对象不再被引用,那么这个对象就会被GC回收,否则这个对象一直会保存在内存中。
在上述例子中,B定义在A中,因此B依赖于A,而外部变量 c 又引用了B, 所以A间接的被 c 引用,
也就是说,A不会被GC回收,会一直保存在内存中。为了证明我们的推理,看如下例子:
| 1 2 3 4 5 6 7 8 9 10 11 12 | functionA(){  varcount = 0;  functionB(){    count ++;    console.log(count);  }  returnB;}varc = A();c();// 1c();// 2c();// 3 | 
count是A中的一个变量,它的值在B中被改变,函数B每执行一次,count的值就在原来的基础上累加1。因此,A中的count一直保存在内存中。
这就是闭包的作用,有时候我们需要一个模块中定义这样一个变量:希望这个变量一直保存在内存中但又不会“污染”全局的变量,这个时候,我们就可以用闭包来定义这个模块
在看jQuery源码:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | (function(window, undefined) {  var  // ...  jQuery = function(selector, context) {    // The jQuery object is actually just the init constructor 'enhanced'    returnnewjQuery.fn.init(selector, context, rootjQuery);  },  jQuery.fn = jQuery.prototype = {    init: function(selector, context, rootjQuery) {      // ...    }  }  jQuery.fn.init.prototype = jQuery.fn;})(window); | 
我们知道了 什么是闭包:当一个内部函数被其外部函数之外的变量引用时,就形成了一个闭包。
jQuery.fn的init 函数被jQuery 的构造函数调用了,这里形成了一个闭包。
构造函数及调用代码:
| 1 2 3 4 5 | // ...  jQuery = function(selector, context) {    // The jQuery object is actually just the init constructor 'enhanced'    returnnewjQuery.fn.init(selector, context, rootjQuery);  }, | 
问题关键来了。
如何实现无new构建
JavaScript是函数式语言,函数可以实现类,类就是面向对象编程中最基本的概念
| 1 2 3 4 5 6 7 8 9 10 | varaQuery = function(selector, context) {    //构造函数}aQuery.prototype = {  //原型  name:function(){},  age:function(){}}vara = newaQuery();a.name(); | 
这是常规的使用方法,显而易见jQuery不是这样玩的
要实现这样,那么jQuery就要看成一个类,那么$()应该是返回类的实例才对
按照jQuery的抒写方式
| 1 2 | $().ready() $().noConflict() | 
要实现这样,那么jQuery就要看成一个类,那么$()应该是返回类的实例才对
所以把代码改一下:
| 1 2 3 4 5 6 7 | varaQuery = function(selector, context) {    returnnewaQuery();}aQuery.prototype = {  name:function(){},  age:function(){}} | 
通过new aQuery(),虽然返回的是一个实例,但是也能看出很明显的问题,死循环了!
那么如何返回一个正确的实例?
在javascript中实例this只跟原型有关系
那么可以把jQuery类当作一个工厂方法来创建实例,把这个方法放到aQuery.prototye原型中
| 1 2 3 4 5 6 7 8 9 10 | varaQuery = function(selector, context) {    returnaQuery.prototype.init(selector);}aQuery.prototype = {  init:function(selector){    returnthis;  }  name:function(){},  age:function(){}} | 
当执行aQuery() 返回的实例:

很明显aQuery()返回的是aQuery类的实例,那么在init中的this其实也是指向的aQuery类的实例
问题来了init的this指向的是aQuery类,如果把init函数也当作一个构造器,那么内部的this要如何处理?
| 1 2 3 4 5 6 7 8 9 10 11 12 | varaQuery = function(selector, context) {    returnaQuery.prototype.init(selector);}aQuery.prototype = {  init: function(selector) {    this.age = 18    returnthis;  },  name: function() {},  age: 20}aQuery().age //18 | 
因为this只是指向aQuery类的,所以aQuery的age属性是可以被修改的。
这样看似没有问题,其实问题很大的
为什么是new jQuery.fn.init?
看如下代码:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | varaQuery = function(selector, context) {    returnaQuery.prototype.init(selector);}aQuery.prototype = {  init: function(selector) {    if(selector=="a")      this.age = 18    returnthis;  },  name: function() {},  age: 20}aQuery("a").age //18aQuery("b").age //18 | 
当我调用 传入"a"的时候,修改age=18,及aQuery("a").age 的值为18
但是当我 传入"b"的时候 并没又修改 age的值,我也希望得到默认age的值20,但是aQuery("b").age 的值为18.
因为在 调用aQuery("a").age 的时候age被修改了。
这样的情况下就出错了,所以需要设计出独立的作用域才行。
jQuery框架分隔作用域的处理
| 1 2 3 4 | jQuery = function( selector, context ) {    // The jQuery object is actually just the init constructor 'enhanced'    returnnewjQuery.fn.init( selector, context, rootjQuery );  }, | 
很明显通过实例init函数,每次都构建新的init实例对象,来分隔this,避免交互混淆
我们修改一下代码:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | varaQuery = function(selector, context) {    returnnewaQuery.prototype.init(selector);}aQuery.prototype = {  init: function(selector) {    if(selector=="a")      this.age = 18    returnthis;  },  name: function() {},  age: 20}aQuery("a").age //18aQuery("b").age //undefinedaQuery("a").name() //Uncaught TypeError: Object [object Object] has no method 'name' | 
又出现一个新的问题,
age  :undefined,
name() :抛出错误,无法找到这个方法,所以很明显new的init跟jquery类的this分离了
怎么访问jQuery类原型上的属性与方法?
做到既能隔离作用域还能使用jQuery原型对象的作用域呢,还能在返回实例中访问jQuery的原型对象?
实现的关键点
| 1 2 | // Give the init function the jQuery prototype for later instantiationjQuery.fn.init.prototype = jQuery.fn; | 
我们再改一下:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | varaQuery = function(selector, context) {    returnnewaQuery.prototype.init(selector);}aQuery.prototype = {  init: function(selector) {    if(selector=="a")      this.age = 18    returnthis;  },  name: function() {     returnage;  },  age: 20}aQuery.prototype.init.prototype = aQuery.prototype; aQuery("a").age //18aQuery("b").age //20aQuery("a").name()  //20 | 
最后在看一下jQuery源码:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | (function(window, undefined) {  var  // ...  jQuery = function(selector, context) {    // The jQuery object is actually just the init constructor 'enhanced'    returnnewjQuery.fn.init(selector, context, rootjQuery);  },  jQuery.fn = jQuery.prototype = {    init: function(selector, context, rootjQuery) {      // ...    }  }  jQuery.fn.init.prototype = jQuery.fn;})(window); | 
是不是明白了?
哈哈哈~~~
在简单说两句:
大部分人初看 jQuery.fn.init.prototype = jQuery.fn 这一句都会被卡主,很是不解。但是这句真的算是 jQuery 的绝妙之处。理解这几句很重要,分点解析一下:
1)首先要明确,使用 $('xxx') 这种实例化方式,其内部调用的是 return new jQuery.fn.init(selector, context, rootjQuery) 这一句话,也就是构造实例是交给了 jQuery.fn.init() 方法取完成。
2)将 jQuery.fn.init 的 prototype 属性设置为 jQuery.fn,那么使用 new jQuery.fn.init() 生成的对象的原型对象就是 jQuery.fn ,所以挂载到 jQuery.fn 上面的函数就相当于挂载到 jQuery.fn.init() 生成的 jQuery 对象上,所有使用 new jQuery.fn.init() 生成的对象也能够访问到 jQuery.fn 上的所有原型方法。
3)也就是实例化方法存在这么一个关系链
1.jQuery.fn.init.prototype = jQuery.fn = jQuery.prototype ;
2.new jQuery.fn.init() 相当于 new jQuery() ;
3.jQuery() 返回的是 new jQuery.fn.init(),而 var obj = new jQuery(),所以这 2 者是相当的,所以我们可以无 new 实例化 jQuery 对象。
实例详解jQuery的无new构建的更多相关文章
- jQuery对html元素的取值与赋值实例详解
		jQuery对html元素的取值与赋值实例详解 转载 2015-12-18 作者:欢欢 我要评论 这篇文章主要介绍了jQuery对html元素的取值与赋值,较为详细的分析了jQuery针对常 ... 
- linux基础-磁盘阵列(RAID)实例详解
		磁盘阵列(RAID)实例详解 raid技术分类 软raid技术 硬raid技术 Raid和lvm的区别 为什么选择用raid RAID详解 RAID-0 RAID-1 RAID-5 Raid-10 R ... 
- 当里个当,免费的HTML5连载来了《HTML5网页开发实例详解》连载(一)
		读懂<HTML5网页开发实例详解>这本书 你还在用Flash嘛?帮主早不用了 乔布斯生前在公开信“Flash之我见”中预言:像HTML 5这样在移动时代中创立的新标准,将会在移动设备上获得 ... 
- C#反射概念以及实例详解【转】
		2009-08-28 13:12 佚名 互联网 我要评论(1) 字号:T | T C#反射概念以及实例向你介绍了C#反射的基本内容以及C#反射实例的简单应用,希望对你了解和学习C#反射以及C#反射实例 ... 
- getElementByID、getElementsByName、getElementsByTagName实例详解
		getElementByID.getElementsByName.getElementsByTagName实例详解 本文通过实例,详细介绍了getElementByID.getElementsByNa ... 
- Bootstrap如何实现导航条?导航条实例详解
		本文主要和大家分享Bootstrap实现导航实例详解,在建设一个网站的时候,不同的页面有很多元素是一样的,比如导航条.侧边栏等,我们可以使用模板的继承,避免重复编写html代码.现在我们打算实现一个在 ... 
- jquery源码学习笔记(一)jQuery的无new构建
		本人是一名.net程序员..... 你一个.net coder 看什么jQuery 源码啊? 原因吗,很简单.技多不压身吗(麻蛋,前端工作好高...羡慕). 我一直都很喜欢JavaScript,废话不 ... 
- Vue 实例详解与生命周期
		Vue 实例详解与生命周期 Vue 的实例是 Vue 框架的入口,其实也就是前端的 ViewModel,它包含了页面中的业务逻辑处理.数据模型等,当然它也有自己的一系列的生命周期的事件钩子,辅助我们进 ... 
- C#实现DevExpress本地化实例详解
		using System; using System.Collections.Generic; using System.Text; using DevExpress.XtraGrid.Localiz ... 
随机推荐
- Flask 编写一个授权登录验证的模块(二)
			本篇比上一篇多了重定向的功能 #!/usr/bin/env python # -*- coding: utf-8 -*- #python3 import base64 import random im ... 
- 【java】简介(一)
			应用:web后端开发.android-app开发.大数据应用开发 学习:java会过时,但程序设计的思想不会过时 特点:1.面向对象,跨平台,语法比c++简单 2.以字节码的形式运行在虚拟机上 3.自 ... 
- tomcat 启动报错org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].xxx
			今天在写完一个非常简单的servlet页面跳转的web项目后,启动tomcat报错org.apache.catalina.LifecycleException: Failed to start com ... 
- Embedded based learning
			简单整理了一些嵌入式底层需要接触的相关概念. # CPU CU. Control Unit. send need-clac-data -> ALU clac -> get resul ... 
- js闭包小实验
			js闭包小实验 一.总结 一句话总结: 闭包中引用闭包外的变量会使他们常驻内存 function foo() { var i=0; return function () { console.log(i ... 
- Flutter移动电商实战 --(14)首页_拨打电话操作
			拨打电话的功能在app里也很常见,比如一般的外卖app都会有这个才做.其实Flutter本身是没给我们提供拨打电话的能力的,那我们如何来拨打电话那? 1.编写店长电话模块 这个小伙伴们一定轻车熟路了, ... 
- 最新react-native(Expo)安装使用antd-mobile-rn组件库
			1\安装antd-mobile-rn 库 npm install antd-mobile-rn --save 2.按需加载 npm install babel-plugin-import --save ... 
- [Java读书笔记] Effective Java(Third Edition) 第 6 章 枚举和注解
			Java支持两种引用类型的特殊用途的系列:一种称为枚举类型(enum type)的类和一种称为注解类型(annotation type)的接口. 第34条:用enum代替int常量 枚举是其合法值由一 ... 
- 使用canal通过mysql复制协议从binlog实现热数据nosql缓存(2)
			开启mysql binlog功能 以5.7版本为例,找到/etc/mysql/mysql.conf.d/mysqld.cnf [mysqld] pid-file = /var/run/mysqld/m ... 
- Impacket网络协议工具包介绍
			转载自FreeBuf.COM Impacket是一个Python类库,用于对SMB1-3或IPv4 / IPv6 上的TCP.UDP.ICMP.IGMP,ARP,IPv4,IPv6,SMB,MSRPC ... 
