<html>
<head>
<script>
var foo='value1';
Object.foo1='value2';
alert(foo+' '+foo1);
</script>
</head>
<body>
<div id="mydiv">
In Div
</div>
</body>
</html>
I have created two properties foo and foo1. Since they are declared at top level they both are actually properties of Object.While accessing these properties in alert function then why i am getting error that foo1 is undefined ? Why at the same time foo
is accessable but foo1 is unaccessable if both are properties belonging to Object ?
I have created two properties foo and foo1. Since they are declared at top level they both are actually properties of Object.While accessing these properties in alert function then why i am getting error that foo1 is undefined ? Why at the same time foo is
accessable but foo1 is unaccessable if both are properties belonging to Object ?
shyam_oec
Member
656 Points
777 Posts
Why top level properties behaving differently ?
Feb 26, 2011 04:46 AM|LINK
HI,
please consider this javaScript code:
I have created two properties foo and foo1. Since they are declared at top level they both are actually properties of Object.While accessing these properties in alert function then why i am getting error that foo1 is undefined ? Why at the same time foo is accessable but foo1 is unaccessable if both are properties belonging to Object ?
vipuldonga
Contributor
3753 Points
692 Posts
Re: Why top level properties behaving differently ?
Feb 26, 2011 06:04 AM|LINK
hi, I think you have do wrong way
you can do this way
<script type="text/javascript"> var foo = "value1"; Object.foo1 = "value2"; alert(foo + ' ' + Object.foo1); </script>Vipul Donga
Mark it as an answer, if it helped
if (MyAnswer)
MarkAsAnswer();
else
Repsonse.Write("correct me where i am wrong");