Hello,
Please consider this bit of code:
Code JavaScript:function Foo() { var obj = new SomeObj(); obj.setBlah("blah"); obj.doSomething(); obj.bar(); return obj; }
Once obj is returned and used outisde the Foo() scope, will it be altered inside the Foo() scope? I'm not sure if I'm clear: I want obj to be "untouchable" within Foo(), I want to only allow modifications of the internal state of the object outside the Foo() scope.
The idea is that if obj is returned a second time, what has been done with the "first return" (so to speak) will not alter the way obj is returned the second time. In other words, I want to make sure that obj is always the same when Foo() returns it.
Is the code above ok, or should I prototype, or make a copy of obj and return that copy?
Hope I was clear enough...
![]()



Reply With Quote



Bookmarks