Javascript object persistency in Meteor js -


supposed created js object

cart = function cart(){     this.contents = new array(); }  cart.prototype = {    add : function(obj){       this.contents.push(obj);    } } 

and put in project lib folder object can used project-wide.

is possible use object persistently in template backend (js file)? example, declared :

template.pagea.rendered = function(){     var smallcart = new cart(); } 

can use in template event? example:

template.pagea.events = {   'click button#add' : function(event){      smallcart.add('newitem'); //is object same 1 in rendered?    } }  

i have been doing stuff using sessions when there lot of operations done, events cluttered business logics , calculations. want avoid this, thinking of putting logics javascript object functions.

will approach work? object stay persistent?

you can place code inside meteor.startup, object persist always.

meteor.startup(function(){  cart = function cart(){     this.contents = new array();  }   cart.prototype = {    add : function(obj){       this.contents.push(obj);    }  } }) 

is object same 1 in rendered? yes


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -