Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
20
rated 0 times [  26] [ 6]  / answers: 1 / hits: 119040  / 12 Years ago, tue, july 31, 2012, 12:00:00

I'm just new comer at Javascript so when I read a Javascript document, and there're many complex structures that I cannot follow.



Here is the short explanation of Javascript code that I'm reading : in my case there are two main files : Helper.js and Circle.js.



In Helper.js, there is a method name :using:function(param1,param2). And below is code for Circle.js:



Helper.using('py.Figures', function (ns) {

ns.Circle = function (params) {
// some additional methods and code here
}

ns.Alert = function(){ // for the test purpose
alert('hello');
}
});


And in file test.html, I write some code like this :



<script src=Helper.js></script>
<script src=circle.js></script>
<script>
test = function(){
py.Figures.Alert(); // calling for testing purpose
}
</script>
<body onload=test();></body>


When I run on Chrome and view in console, I meet this error :




Uncaught TypeError: Object # has no method 'Alert'




It means I haven't import those class, yet. Please tell me how to calling function from another file. In my case is : calling Alert()



Thanks :)



@ Edit: I have added some links for the code :



Helper.js



Circle.js


More From » javascript

 Answers
21

Why don't you take a look to this answer



Including javascript files inside javascript files



In short you can load the script file with AJAX or put a script tag on the HTML to include it( before the script that uses the functions of the other script). The link I posted is a great answer and has multiple examples and explanations of both methods.


[#83939] Monday, July 30, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devonw

Total Points: 311
Total Questions: 116
Total Answers: 111

Location: Senegal
Member since Fri, Aug 21, 2020
4 Years ago
;