Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object Scope

Status
Not open for further replies.

mjpearson

Technical User
Dec 13, 2002
196
0
0
US
I'm new to JavaScript and confused about the scope of objects.

When you define an object in a script, can it be accessed from another script? Or do I need to define it as a document object?

In otherwords:

<script1>
var object1 = objectdefinition();
</script1>
<script2>
object1.method1();
</script2>

-or- do I need to preface the object with "document."

<script1>
var document.object1 = new objectdefinition();
</script1>
<script2>
document.object1.method1();
</script2>


mike
 
Objects are like variables -- they exist as part of the window object, no matter their type.

--Chessbot

"So it goes."
Kurt Vonnegut, Slaughterhouse Five
 
I'm not 100% sure, but you might try this:
<script1>
var object1 = objectdefinition();
</script1>
<script2>
document.object1.method1();
</script2>
(with the 'document.' added to "script2" from your original) If you need any further help just ask and I'll do my best.

It's ok to ask questions, the only bad questions are the ones not asked.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top