Been reading Javascript Design Patterns from Addy Osmani, and in the document this simple assignment is used to 'prevent overwriting an already existing object/ namespace':
var myNS = myNS || function() {};
So I understand it assigns the same object to the variable if it already exists, or creates an empty one if it (ideally) doesn't. So suppose I add a method to this object's prototype, but an already-existing, similarly-named object already had a similarly-named method that outputted 'Hi!'. The following should happen, right?
myNS.prototype.sayHello = function() { return 'Hello!' };
myNS.sayHello(); // Hello! ??
And the original myNS.sayHello() // Hi!
is still overwritten, no? So i.e. what does conditional variable assignment in this case do, except add one level of name-collision avoiding ? Or am I completely wrong on this?