(Partial) Extending "functions" in javascript? -


i have code...

var = {         helpers: {                 getname: function() {             return 'john doe';         }            }     }  // in file...  var = {         helpers: {                 getage: function() {             return '40';         }            }     }  // test...  $("#mydiv").html(my.helpers.getname + " " + my.helpers.getage); 

http://jsfiddle.net/mojodk/8cmv7/

... getname undefined.

i hoping javascript smart enough merge this...

var = {         helpers: {                 getname: function() {             return 'john doe';         },          getage: function() {             return '40';         }     }     } 

how extend method (or it's called) above? have several "helper" files, needs "merge".

redundancy this:

my = window.my || {}; my.helpers = my.helpers || {}; my.helpers.getage = function() {     return 40; }; 

demo of in action


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -