0409笔记

1、

绝大多数对象最终都会继承自Object.prototype
例外:一切对象的原型是一个对象或者null,所以不是所有对象的最终都会继承自Obeject.prototype.
Object.create(null);

2、

call/apply 

改变this指向

function Person(name,age){    this.name = name;    this.age = age; } var person = new Person("chen",18); var obj = {}; Person.call(obj,"li",20);

function Person(name,age,sex){        this.name = name;        this.age = age;        this.sex = sex;     }    function Student(name,age,sex,tel,grade){         Person.apply(this,[name,age,sex]);//apply传进的参数为一个数组         this.tel = tel;        this.grade = grade;     }      var student = new Student('sunny',123,'male',139,2017);

3、

闭包可以用在许多地方。它的最大用处有两个,一个是前面提到的可以读取函数内部的变量,另一个就是让这些变量的值始终保持在内存中,不会在f1调用后被自动清除。

为什么会这样呢?原因就在于f1是f2的父函数,而f2被赋给了一个全局变量,这导致f2始终在内存中,而f2的存在依赖于f1,因此f1也始终在内存中,不会在调用结束后,被垃圾回收机制(garbage collection)回收。

使用闭包的好处:

-希望一个变量长期驻扎在内存当中;

-避免全局变量的污染;

-私有成员的存在

https://www.cnblogs.com/jingwhale/p/4574792.html

4、看来这种也得在家弄完再发

js 里没有块级的

function outputNumbers(count){
for (var i=0; i < count; i++){
//console.log(i);
   }

console.log(i);
}

outputNumbers(3)

(function(){

//这里是块级作用域

})();

模拟块级并立即执行:

this 的多种用法,to thi tha

原文地址:https://www.cnblogs.com/cnchengv/p/10679359.html