Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2013
    Posts
    44
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Combine External and Internal JS

    I am trying to include a reference to an external .js file to use some functions and I have some internal functions.

    When I reference the external file those functions work fine but my internal ones are "undefined"


    Is there a proper way to reference an external .js file and still have internal functions?

    Never mind I got it , I was NOT closing out the external script properly

    Thank you
    Last edited by billboy; 02-18-2013 at 01:14 AM. Reason: Solved

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,465
    Thanks
    0
    Thanked 634 Times in 624 Posts
    With JavaScript it makes no difference whether the code is internal or external to the page. What matters is the order you define the code.

    If you define functions using this method:

    funcname - function() {...}

    then the function exists from when that statement executes until the end of the current scope or a different value is assigned to funcname.

    If you define a function using this method:

    function funcname() {...}

    then the last declaration of funcname will be the one used and the earlier one will be ignored (unless they are nested inside of other different functions.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •