I had to use new new when using an object as a namespace. Although it will be better:
Instead:
var Namespace = function() { var ClassFirst = this.ClassFirst = function() { this.abc = 123; } var ClassSecond = this.ClassSecond = function() { console.log("Cluttered way to access another class in namespace: ", new new Namespace().ClassFirst().abc); console.log("Nicer way to access a class in same namespace: ", new ClassFirst().abc); } } new new Namespace().ClassSecond()
Do it:
var Namespace = new function() { var ClassFirst = this.ClassFirst = function() { this.abc = 123; } var ClassSecond = this.ClassSecond = function() { console.log("Cluttered way to access another class in namespace: ", new Namespace.ClassFirst().abc); console.log("Nicer way to access a class in same namespace: ", new ClassFirst().abc); } } new Namespace.ClassSecond()
Not directly related to the question, but I was googling new new javascript because it looked pretty ugly and wrong. This post may help to avoid creating an unnecessary object for other new new Google'ers.
source share