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

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -