es5核心技术

立即执行函数

    (function () {
        console.log(111)
    })()

函数提升和变量提升

    var a = 12;
    (function () {
        var a = 13;
        function a(){

        }
        console.log(a)//13
    })()
//function 声明在变量之前

闭包

//闭包形式
function out(){
    var a = 12;
    function inside(){
        a++;
        console.log(a)
    }
    return inside;
}
var global = out();
global()//13
global()//14
//闭包概念 函数被调用在他所在的词法作用域之外,保留了对原词法作用域的引用,形成了闭包
//好处  模块化开发 实现私有变量 避免全局变量的污染
//缺点  造成内存泄漏  需要将引用变量 = null

this

var a = 13;
var test = {
   a :12,
   init:function (argument) {
       console.log(this.a)
   }
}
test.init()//12  this指向test
var global = test.init;
global()//13    this指向window
//this  指针 谁调用指向谁
//改变this指针 call apply bind  
//call  参数直接,,,  apply 参数数组  bind返回新函数 this不能再被改变  未执行

原型链实现继承

function Person(name){
    this.name = name;
}
Person.prototype.speak = function(){
    console.log("我叫"+this.name)
}

function Student(){
    Person.call(this);
}

Student.prototype = Object.caeate(Person.prototype)
Student.prototype.constructor = Student;
//对象的_proto_指向创造函数的原型对象最终_proto_指向Object.prototype
//函数的原型对象是 有constructor 和 各种原型上的方法  construtor函数是构造函数本身 

你可能感兴趣的:(es5核心技术)