Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
128
rated 0 times [  135] [ 7]  / answers: 1 / hits: 85814  / 11 Years ago, thu, february 28, 2013, 12:00:00

I have 2 separate javascript files



#1.js
String.prototype.format = ....
String.prototype.capitalize = ....

#2.js

//................
var text = some text{0}.format(var1)
//................


How do I make string#format and string#capitalize available in the second file?


More From » javascript

 Answers
13

JavaScript executes globally. Adding both scripts on the page makes them available to each other as if they were in one file.



<script src=1.js></script>
<script src=2.js></script>


However, you should note that JavaScript is parsed linearly and thus, first parsed, first served. If the first script needs something in the second script, but the second script hasn't been parsed yet, it will result in an error.



If that happens, you should rethink your script structure.


[#79935] Wednesday, February 27, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
harleyaleenag

Total Points: 678
Total Questions: 121
Total Answers: 105

Location: Papua New Guinea
Member since Thu, Jul 9, 2020
4 Years ago
harleyaleenag questions
Thu, May 5, 22, 00:00, 2 Years ago
Wed, Aug 19, 20, 00:00, 4 Years ago
;