javascript - Including Helper Functions in Separate JS File (Client-Side) -


first off, know pretty low-level part, i'm sorry not trying before asking this.

what methods guys suggest including helper functions in separate files? i'm used node.js's module interface doing this, i'm not 100% on how achieve similar functionality client-side.

small example of i'd abstract own file:

var helpers = (function() {   var _helpers = {};    _helpers.builddatefromdelta = function(delta) {     date = new date();     date.setdate(date.getdate() - delta);     date.sethours(0, 0, 0, 0);      return date;   };    return _helpers; })(); 

not sure if you're looking but, (this assuming you're running on html page)

var s = document.createelement("script"); s.src = "external.js"; document.getelementsbytagname("head")[0].appendchild(s); 

this code goes in main js file.
hope helps!


Comments

Popular posts from this blog

javascript - JS causing window size to be bigger than necessary - Dropdown bug -

How to mention the localhost in android -

php - Calling a template part from a post -