Do object references (as opposed to copies) ever "expire" if they are
passed around too much (e.g., if called/applied in a different 'this'
scope)? I really don't think I'm making copies so I don't see how this
information could get lost, and I have seen this work a lot of the time,
but it periodically does give me errors about such variables being
undefined...
For example, I'm adding observers like:
var debug = function (m) {alert(m);};
obj.addObservers({
action1 : function () {
debug('warning'); // Debug should be in scope but I sometimes
get errors saying debug is undefined
}
action2 : function () {
debug('warning 2');
}
});
(Btw, addObservers() in addition to storing the functions in arrays
according to the action topic name, will also keep a reference to the
notifying object so that the specific observer functions will later be
run in that object's scope. Does my problem possibly have anything to do
with references being what I have seen called "weak", and if so, how
might I overcome them being treated this way?)
thanks,
Brett
--
Documentation: http://github.com/bard/sameplace/wikis/home
Discussions: http://groups.google.com/group/sameplace
Bug tracker: https://bugs.launchpad.net/sameplace
Since Javascript 2 is science-fiction for now, I could suggest you tu place all your libraries inside some kind of "package".
Just define
MyLibObj = {
mycustomfunc : function () { /*blah*/ },
debug : function (m) { alert(m); }
}
That way your "debug" function will not be overwritten, as it is too difficult to find a software that uses and defines another time "MyLibObj".
This way you also avoid scope pollution :)