Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
254 views
in Technique[技术] by (71.8m points)

javascript - 如何在窗口对象之外创建JavaScript对象?(How to create JavaScript object outside of a window object?)

Is it possible to create a js object that is not under the window object?

(是否可以创建不在window对象下的js对象?)

If yes, then how?

(如果是,那怎么办?)

There is a different ongoing discussion when I'm trying to understand the location of _internalRoot object created by ReactRoot() constructor.

(当我试图了解ReactRoot()构造函数创建的_internalRoot对象的位置时,有一个正在进行的讨论 。)

Good people say that most probably it's not under the window object.

(好人说,这很可能不在window对象下。)

I was sure that we could not create an object outside of a window object.

(我确定我们无法在window对象之外创建对象。)

  ask by platinum_ar translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Just create the object in a local variable:

(只需在局部变量中创建对象:)

function example() {
    var demo = {};
}
example();

Even if example is a global variable and somehow tied to window , the demo variable is not.

(即使example是全局变量并且以某种方式与window绑定, demo变量也不是。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...