Monday 15 March 2010

RequireJS: returning total function but I need the value, because it is a date module? -



RequireJS: returning total function but I need the value, because it is a date module? -

i creating module this. because date object, writing code in return block. otherwise giving same time. so, want if @ all, wants functionality respect day, date or property, have written function giving total function response:

class="lang-js prettyprint-override">define([], function() { var dayarr = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]; homecoming { date: new date().getdate(), day: dayarr[new date().getday()], year: function() { new date().getfullyear(); }, time: new date().gethours() + ":" + new date().getminutes() + ":" + new date().getseconds() } });

response property year:

class="lang-js prettyprint-override">function () { new date().getfullyear(); // , calculation code }

but want year.

i followed link: http://jsperf.com/requirejs-return-object-vs-return-new-instance, giving total function.

its not clear trying do.

you defined year property function, back. need execute function.

require(["mydatemodule"], function (mydatemodue) { var year = mydatemodule.year(); });

if don't want function, don't define function, did date, day, , time. fields have computed values too.

remember function define module called 1 time, first time module loaded, returned value cached , used other requests module. means same date everywhere module loaded.

if trying new date or run new calculations every tie module loaded, maybe want homecoming function module instead?

define([], function() { var dayarr = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]; homecoming function() { var date = new date(); homecoming { date: date.getdate(), day: dayarr[date.getday()], year: date.getfullyear(); time: date.gethours() + ":" + date.getminutes() + ":" + date.getseconds() } } }); require(["mydatemodule"], function (mydatemodue) { var date = mydatemodule(); var year = date.year; });

module requirejs

No comments:

Post a Comment