coding style - What is the name/term for structuring JavaScript in this way? -


i've been writing javascript particular style last year or in work (example below) , wondering if tell me style or pattern called. assume has name it's 1 of things if don't know call it's tough find on it.

var page = {     dostuff: function ()     {         // stuff gets done here     },      save: function ()     {         // save logic     }  }; 

the above js can called this:

page.save(); 

we've been using means can kind of namespace functions if every page has save function can called same name never conflict.

apologies if has been asked before said it's hard find answer when i'm not sure keyword using.

update speedy response everyone. have 1 more question on if can help. had tried sort of function overload in past have this:

var page =  {     dostuff: function ()     {         // stuff     },      dostuff: function (name, type)     {         // stuff name , type params     } }; 

but functions end overriding each other last 1 read in replaces other , end 1 function instead of being able call both

page.dostuff(); page.dostuff('lews0r', 'newbie'); 

is possible overload functions in namespacing/module structure? or have stick naming second function different page.dostuff2() (and award best function name ever goes to...).

usually, think people refer these "modules". "namespaces" may fitting term - containing functions inside either product name, library name, or company name, can avoid putting many labels in global namespace.

nadh suggested "object oriented programming"; think difference in object-oriented programming, define class, not object - tell program how can create many instances of page, modified in little ways, like. javascript libraries offer various ways of doing this. if you're directly assigning page "an object these functions", tend think of more "module". that's approximately how languages python tend work.

there may not quite official name of these practices, since personal belief ecmascript (javascript)'s original designers had never quite anticipated ways used; people got inventive.


Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -