javascript - set a Module property only once -
i have module :
var module = (function() { var id; var setid = function(a){ if(a) id = a; else id = undefined; }; var getid = function(){ return id; }; // return object assigned module return { setid: setid, getid: getid }; }()); in i'm setting id member through setid() function.
i wondering: in way, setid public member of module, , can called every other module inside application. set id once, , avoid other call of setid() set value must setted once. there way?
i'm new module design pattern please excuse me nubbishness.
you modify setid nothing if id set:
var setid = function(a){ if(typeof != 'undefined' && typeof id == 'undefined') id = a; }; then other modules still call it, nothing (or make throw error or return false instead).
Comments
Post a Comment