我有这段代码,当我运行它显示未定义。但是,我们可以使用此关键字访问全球资产。为什么我得到undefined值
var firstName = "Peter",
lastName = "Ally";
function showFullName() {
// "this" inside this function will have the value of the window object
// because the showFullName() function is defined in the global scope, just like the firstName and lastName
alert (this.firstName + " " + this.lastName);
}
showFullName();
http://jsbin.com/gerexi/1/edit?js,输出 - 我无法重现该问题。 – Quentin
我既不好也不好 –
在严格模式下,它只是抛出一个错误。如果这是放置另一个函数,那么它会显示“undefined undefined”。 – vlaz