javascript - Why we should check for the variable being defined var m = m || function(){} -
lot of libraries have seen methods defined this
common.deepcopy = common.deepcopy || function(oldobject) { return $.extend(true, {}, oldobject); }; what need of defining methods objects this.
because js files executed once there no chance of deepcopy being defined previously.
that's not case. never know whether js file included twice or whether initialized again. better check whether object exists , assign if does. otherwise create new object
Comments
Post a Comment