or operator - What is the meaning of these statements || {} in this javascript code -
this question has answer here:
i'm getting going in javascript , reading on module pattern.
i have been looking @ page: http://www.adequatelygood.com/javascript-module-pattern-in-depth.html , cannot work out || {} statements mean.
there quite few places code written: (util || {}));
can explain these statements mean , doing?
i assume || means or - not in context.
here code conclusion of article. second , penultimate lines examples of code has me puzzled.
var util = (function (parent, $) { var = parent.ajax = parent.ajax || {}; my.get = function (url, params, callback) { // ok, i'm cheating bit :) return $.getjson(url, params, callback); }; // etc... return parent; }(util || {}, jquery));
this used define variable if not set. can ensure there value set!
for example:
function ihaveparameters(param1, param2) { param1 = param1 || {} //empty object param2 = param2 || "this should string" }
and of course noted, invoke second value when first variable null.
and in case setting variable when it's not set, meaning if include script 3000 times, variable still defined once avoiding cpu. way require loading of function example
Comments
Post a Comment