Ad
  • Custom User Avatar

    I understand your concern about falsy values, but this does not fix this (unlikely) scenario. In case MyNamespace is 0 (or any other primitive value) your code would fail on this line:

    MyNamespace.MyClass.prototype.sayHello = function () { return this.string; }
    

    Since MyClass reference will be discarded right after the number is coerced to an object. Another example below:

    var n = 0;
    n.MyClass = function(){}
    n.MyClass.prototype.sayHello = function(){} //TypeError: Cannot read property 'prototype' of undefined