0

Not sure if I'm wording this correctly but can local variables inside a sealed object pass information to global variables?

Kahless
  • 1,213
  • 2
  • 13
  • 31
  • What do you mean by 'pass information'? Do you mean to ask if they can modify or set values to global variables? – Robbie Wxyz Sep 22 '13 at 01:07
  • Yes. lets say var hello = 2 is the global variable and there's a function within a sealed object. And inside the function is var hello = 3. Should it update the global variable to 3? – Kahless Sep 22 '13 at 01:12
  • correction. within the function is hello = 3 not var hello = 3. – Kahless Sep 22 '13 at 01:15
  • What's a "sealed object" ? You can easily write a piece of code that tests it! – Nir Alfasi Sep 22 '13 at 01:21
  • Sorry I'm still very new to this. This page will explain it better. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal – Kahless Sep 22 '13 at 01:32

1 Answers1

0

Yes, they can:

var hello = 0, obj;

obj = {
  foo: function () {
    hello = 3;
  }
};

Object.seal(obj);

console.log(hello); //logs 0
obj.foo();
console.log(hello); //logs 3

Here's a jsfiddle.

Bjorn
  • 69,215
  • 39
  • 136
  • 164