0

I need a solution for managing js files in my project.

Is there any way that i can reference a js file like this in my html?

<script>
   var someName = use("somejsfile.js")
</script>

And to use it like this

<input onclick="someName.saveThisInput()">

Currently the js file in my project is made like this:

$( document ).ready(function() {});

var abc = "some global var";
// a lot of other globals

function saveThisInput(){}
function saveThisInput1(){}
function saveThisInput2(){}

EDIT

I can't make any changes to the preexisting js files so require.js won't work. My goal is to merge two or more such js files having name conflicts

6
  • Possible duplicate of How to manage client-side JavaScript dependencies? Commented Feb 7, 2016 at 14:29
  • What's the ultimate purpose? In what environment/context are you trying to load individual files? What's the problem you're trying to solve? Commented Feb 7, 2016 at 14:29
  • The js files i am supposed to work with are a mess. They are giant ugly beasts that i have to work with. I want namespaces so that my current module will use the namespace object instead of the global variables coming from those files. Commented Feb 7, 2016 at 14:35
  • @AnshuSrivastava fix those "ugly beasts" files so they do everything in their own closure and explicitly set things needed to be externally referencable ;(function () { /* do stuff */ ; if(!window.fileNameSpace) window.fileNameSpace = someGeneratedObject;}()); Commented Feb 7, 2016 at 14:47
  • I simply don't have that kind of time and that would confuse other people. Commented Feb 7, 2016 at 14:56

1 Answer 1

0

you can use namespace in js edit the js file to look like:

var hello = {

  world: function() {
      alert("hello world!");
  },

  foo: function() {
      alert("foo");
  }
};

and use it like:

hello.world();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.