Hmmm... I don't see much difference. You can still get access to 'obj' from the return value of the call to modifyobj()... and then directly update it. This particular example only disallows accidental usage of 'obj'... which is useful in many cases.
Just thought I'd point this out for anyone thinking that the 'obj' instance is being hidden or protected in some manner by this example. This example is a great example of not advertising the internals of some object to the global scope... which is extremely useful in many cases.
Hmmm... I don't see much difference. You can still get access to 'obj' from the return value of the call to modifyobj()... and then directly update it. This particular example only disallows accidental usage of 'obj'... which is useful in many cases.
Just thought I'd point this out for anyone thinking that the 'obj' instance is being hidden or protected in some manner by this example. This example is a great example of not advertising the internals of some object to the global scope... which is extremely useful in many cases.
Ack, you're right. The closure should not be returning the object.
The example was meant to illustrate how to prevent global scope pollution if you had a need for that. Slight mis-fire on my part.