续前节js
继承 :继承某个对象的原型
【在原型空间上加东西,继承者的空间同理也加东西】
【如果既要继承别人的原型,又要自身加东西不影响别人,中间加个过度】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | Father.prototype.Lastname = 'nimeng'; function inherit(Target,Oringin){ var F = function () {}; return function(Target,Oringin){ F.prototype = Oringin.prototype; Target.prototype = new f(); } // function Son(){ // }; // function Father(){ // }; // inherit(Son,Father); |
命名空间: 管理变量 防止污染全局,适用于模板化开发【命名空间,闭包{私有化}】- 实现链式调用模式【obj.eat().smoke().drink().perm().sleep();】
属性的表达方式 :1.bgj.prop 2.obj[‘prop’]
-遍历: obj.name-------obj[‘name’]【for里面一定写[ ]】
对象的枚举:
1. for in
2. hasOwnproperty
3. in
4. instanceof
A instanceof B:
- A对象 是不是 B构造函数构造出来的
- 看A对象的原链上 有没有B的原型
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | var nimeng = { name:'xiaoliu', age:19, sex:"male", height:160, weight:75, } var prop; for(prop in fenda){ if(fenda.hasOwnproperty(prop)){ console.log(nimeng[prop]); } } |
Typeof返回的结果可能有 :
1. 字符串
2. function
3. number
4. object
5. undefined
6. 布尔值
(后期小编会写关于jQuery的返回结果,你意想不到的结果)
1.函数与编译过程 ------ window
2.全局作用域里this ------ window
3.call/apply可以改变函数运行时this的指向
4.obj.func() func()里面的this指向obj
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | var nimeng = { smoke:function(){ console.log('peipei'); return this; }, drink:function(){ console.log('nice!'); return this; }, perm:function(){ console.log('cool'); return this; }, sleep:function(){ console.log('goodnight!'); return this; } } nimeng.smoke().drink().perm().sleep(); |
this简单描述:
1.谁调用this指向谁
2.没有调用就是指向全局或者undefined
var num = (function(n){
if(n == 1){
return 1;
}
return n*arguments.callee(n-1);
}(20))
1 2 3 4 5 6 | var num = (function(n){ if(n == 1){ return 1; } return n*arguments.callee(n-1); }(20)) |