Answer the question
In order to leave comments, you need to log in
how to deal with namespace in javascript?
I don't quite understand how to use namespaces in javascript.
Tell me why the highlighted line is needed or is not needed at all in this code?
var app = app || {}; // эта строка
function app(){}
app.prototype={
init: function (param){
},
connect: function(){
}
}
Answer the question
In order to leave comments, you need to log in
Tell me why the highlighted line is needed or is not needed at all in this code?Since there are no native namespaces in js, this is the way to "emulate" them. But given that the function of the same name is then declared, inside which the prototype is also redefined, the above code is complete crap.
var app = app || {};
app.myModule = (function () {
connect: function(){}
})()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question