美文网首页
this & new

this & new

作者: 青城墨阕 | 来源:发表于2021-06-24 17:25 被阅读0次
this
  1. this:
    • 全局this -------> window
    • 局部(函数)this -------> 调用其的对象
    • 构造函数this -------> 当前构造函数的实例对象
  2. 特殊的this: call apply bind 修改的this(详细可见: call、bind、apply的手动封装)
    function fun() {
        console.log(this);
    }

    var obj = {
        fun: function() {
            console.log(this);
        }
    }

    fun(); // this ----> window (1. 自调用(相当于window.fun())
    new fun(); // this ----> 实例对象
    obj.fun(); // this ----> obj
    fun.call(obj);  // this ----> obj


new
  1. 创建空对象
  2. 执行函数
  3. 确认this指向创建的空对象
  4. 返回执行的结果
function Person(name, age) {
    this.name = name;
    this.age = age;
}
let p = new Person(‘bob’, 30);

相关文章

  • New place, New day, New life

    今早五点钟醒来 —可并不是澳大利亚的五点钟 而是在美国奥兰多Orlando的时间:八月七号的早晨五点钟。现在的澳洲...

  • New month,new start and new self

    今日复盘 1.早起5:26√ 2.口语晨读√ 3.演讲练习×(出席升国旗活动,推掉) 4.健身√ 5.大物复习+作...

  • I see

    New year, new life, new ways and new opportunities. It’s ...

  • git中拉代码下来冲突中的<<<<<<< head

    <<<<<<< HEAD new new new new code ======= old old old cod...

  • a new voice, a new world

    昨晚的西部世界出现了一个新的世界,一个幕府世界,但剧情和西部世界甜水镇的剧情是差不多,而拍摄的是镜像,这就像两个平...

  • NEW LIFE, NEW START

    即将踏上一段新的征途,告别了过去的自己,我,在这里,在一个新的起点。 三年前,我满怀斗志,却渐渐迷...

  • New job,new start

    我换工作了。简短的一句话里饱含着无数无奈,我不能大声宣扬,我也没有告诉多少人,包括生命里重要的那些人,也包括以前的...

  • A  new life  OR   A new star

    鲁迅先生弃医从文的时候,在日本办的杂志名称叫作《新生》,我总觉着,中文中“新的开始”不如英文中“A new l...

  • New day new life!

    This afternoon I bought a new iPad ,it's very easy to use...

  • New Job,New Knowledge

    Lesson 1 About You and Your Job After this lesson,you sho...

网友评论

      本文标题:this & new

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