首页 > 其他 > 详细

this

时间:2018-08-05 11:22:47      阅读:158      评论:0      收藏:0      [点我收藏+]

 

"use strict";

function Greet(name) {

    this.name = name;

    this.sayHello = function () {

        console.log("Hello " + this.name);

    };

}

var greet = new Greet("tom");

greet.sayHello();

输出:Hello tom

 

 

 

"use strict";

function Greet(name) {

    this.name = name;

    function sayHello() {

        console.log("Hello " + this.name);

    }

    return {

        name: "cat",

        sayHi: sayHello

    };

}

var greet = new Greet("tom");

greet.sayHi();

 

输出:Hello cat

 

 

"use strict";

function Greet(name) {

    var that = this;

    this.name = name;

    function sayHello() {

        console.log("Hello " + that.name);

    }

    return {

        name: "cat",

        sayHi: sayHello

    };

}

var greet = new Greet("tom");

greet.sayHi();

 

输出:Hello tom

 

this

原文:https://www.cnblogs.com/yasepix/p/9424738.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!