Bless-L / MyBlog

时不时会写一些文章
23 stars 2 forks source link

JavaScript的一些语法细节 #1

Open Bless-L opened 8 years ago

Bless-L commented 8 years ago

JavaScript的一些语法细节


    var obj = new foo();
    //相当于
    var obj = {};
    obj.__proto__ = foo.prototype;
    var x=1;
    foo = function(){
        this.x=2;
        this.set =function(){
            setTimeout(console.log(this.x),0)
            }
            this.sett = function(){
            setTimeout(function(){
                console.log(this.x)
            },1000)
        }
    }
    var f = new foo();
    f.set(); //输出2
    f.sett();//输出1