Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

this那篇习题答案有误#1062

Answeredbysonghn233
xiaowangge666 asked this question inQ&A
Discussion options

   在this那篇教程上说下方代码是会报错 因为this是undefined 但是实际不会

function makeUser() {
return {
name: "John",
ref: this
};
}

    let user = makeUser();    alert(user.ref.age);
You must be logged in to vote

Hello,本教程已经说明

本教程的所有例子都默认采用严格模式,除非特别指定(非常少)。

在严格模式下 global 不会把 this 设置为 globalThis,而是为 undefined

P.S. 同时可以把这个理解为默认行为,因为在现代前端开发绝大部分上下文都是暗含了开启严格模式的。

Replies: 1 comment

Comment options

Hello,本教程已经说明

本教程的所有例子都默认采用严格模式,除非特别指定(非常少)。

在严格模式下 global 不会把 this 设置为 globalThis,而是为 undefined

P.S. 同时可以把这个理解为默认行为,因为在现代前端开发绝大部分上下文都是暗含了开启严格模式的。

You must be logged in to vote
0 replies
Answer selected bysonghn233
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@xiaowangge666@songhn233
Converted from issue

This discussion was converted from issue #1061 on June 19, 2022 16:58.


[8]ページ先頭

©2009-2025 Movatter.jp