I am writing some JavaScript files that will not be used with HTML documents. For example, writing a calculator in one JavaScript file, where I'll have different .js
files say one for addition, subtraction, multiplication, division, etc..
I'd like to have each math operation in a self contained .js
file then have another .js
file that will #include the other smaller files and can call the functions from them?
Is that possible?
Answer
Using javascript:
var script = document.createElement('script');
script.src = '/js/script';
document.head.appendChild(script);
Using jQuery:
//you need to change your path
$.getScript('/js/script.js', function()
{
// script is imported
});
No comments:
Post a Comment