this 指向

作者: adminlyrics | 来源:发表于2017-07-27 16:38 被阅读5次

this执行全局环境中 this 指向 window

this很重要的解析

https://segmentfault.com/q/1010000004563202

匿名函数中this 指向 window

function (){

this --->window

}

var Temp = function(){

this->window;

}

在一个对象中封装了一个函数,这个函数this 指向 这个对象

var  object = {

name:"ZZZ",

obj :function(){

this->object;

}

}

还有就是先创建一个对象 var object;

object .a="kkk";

object.b=function(){

this->obj;

}

//注意上下区别

new 一个实例,this 指向那个获得实例的对象

function B(){

       name ="BO";

        age=19;

          function C(){

                      console.log("HELLO");

             }

       C();//调用C函数

}

B.name; //B,函数名 .name 是函数名本身,不是内部属性的name 字段

B.内部属性是错误的,B内部属性B函数执行完就会销毁,

外部是访问不到的;

实例只能访问到原型链上的属性,访问不到内部属性

var T = new B();//B的this ->T输出 HELLO(内部调用了C()函数)

T.name//undefine 

T不能访问到name,age ,C();

B.prototype.getName=function(){

             console.log(this.name);

}

B.getName();//ERROR

T.name="TT";

T.getName();//TT;

T.Age =999;

B.prototype.Age=333;

T.Age;//333?999

T._proto_//object 

T._proto_.construct //function B();

相关文章

  • this指向以及改变this指向

    改变this指向 call() apply() bind()

  • this指向

    this指向: 简单的一句话,谁调用的函数,this就指向谁 例子: var obj = { fun1: func...

  • this指向

    axios.get('/api', {params: {name: "kerwin",age:100}}).the...

  • this指向

  • this指向

    例 例

  • this 指向

    window.name = 'xiaoyu' var myObj = {name: 'seven',getName...

  • 指向

    平静的海托着翻飞的火焰,离开港口就有多少离人的泪还会再次上演,看着手上的钟表计算着离开的航线,肃穆的夜还有一串星火...

  • this 指向

    this执行全局环境中 this 指向 window this很重要的解析 https://segmentfaul...

  • this指向

    // 在普通函数中,函数的调用者是window对象,所以函数中的this指针指向的是window,通过访问this...

  • 指向

    飘飘荡荡,所有的事情都在直指一个方向 珍惜所有的付出,不在一处能回馈的也必会找到另一种方式。愿长长久久

网友评论

    本文标题:this 指向

    本文链接:https://www.haomeiwen.com/subject/xxfzkxtx.html