aspose file tools
The moose likes HTML, CSS and JavaScript and the fly likes javascript import Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "javascript import" Watch "javascript import" New topic
Author

javascript import

Stu Johns
Ranch Hand

Joined: Aug 11, 2008
Posts: 63
Hi, I have 2 javascript files
test1.js and test2.js
I want to call a function in test1.js from a function in test2.js
So i need to do something similar to a java import.
Can this be achieved?

thanks

Stu.
Zaeed McColin
Ranch Hand

Joined: Jan 13, 2009
Posts: 90
it's easy to call a function from another function
for example function a() from 1.js want call function x() from 2.js
OK look
code for a():

and code for x():


so as you see calling methods(functions) not so hard

and about link(import) 1.js and 2.js to document
it's as easy as ABC
just in your head add these guys




Open source
Stu Johns
Ranch Hand

Joined: Aug 11, 2008
Posts: 63
thats great, thanks.

Stu
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56529
    
  14

Once both files are included in the page, they all become part of the same scope.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15362
    
    6
If you are not sure that a file is added you can do a simple check

if(typeof foo !== "undefined"){ alert("nope"); }

and you can add it in with document.createElement

Eric
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: javascript import
 
Similar Threads
Javascript Variable scope
help!
Regarding Package
Question about document ready block
js references/garbage collection/other questions