ReferenceError: […] is not defined











up vote
0
down vote

favorite












I am trying to use a JS function which is in an another JS file and I have this error :




ReferenceError: Lanceur is not defined




Lanceur is my object which is defined in my second file.
I have a constructor :



public class Lanceur { 
constructor(angleAiguille) {
this.angleAiguille = angleAiguille;
} // And functions .....


I have this line in my first file : lanceur = new Lanceur(0);



And I call my files in a HTML files with <script src="js/canvas.js" type="text/javascript"></script>, for example.










share|improve this question




















  • 2




    You need to load the class before making an instance from it. So if the class is in the second file and the new Lanceur() call in the first, you need to swap the files around.
    – Shilly
    Nov 21 at 15:20






  • 1




    Are you compiling this with something? Your use of public confuses me, are you sure you don't mean class Lanceur { }?
    – James Ives
    Nov 21 at 15:22












  • Thank you Shilly and James. Now, how I call my functions ?
    – Vincent Bourdon
    Nov 21 at 15:25

















up vote
0
down vote

favorite












I am trying to use a JS function which is in an another JS file and I have this error :




ReferenceError: Lanceur is not defined




Lanceur is my object which is defined in my second file.
I have a constructor :



public class Lanceur { 
constructor(angleAiguille) {
this.angleAiguille = angleAiguille;
} // And functions .....


I have this line in my first file : lanceur = new Lanceur(0);



And I call my files in a HTML files with <script src="js/canvas.js" type="text/javascript"></script>, for example.










share|improve this question




















  • 2




    You need to load the class before making an instance from it. So if the class is in the second file and the new Lanceur() call in the first, you need to swap the files around.
    – Shilly
    Nov 21 at 15:20






  • 1




    Are you compiling this with something? Your use of public confuses me, are you sure you don't mean class Lanceur { }?
    – James Ives
    Nov 21 at 15:22












  • Thank you Shilly and James. Now, how I call my functions ?
    – Vincent Bourdon
    Nov 21 at 15:25















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am trying to use a JS function which is in an another JS file and I have this error :




ReferenceError: Lanceur is not defined




Lanceur is my object which is defined in my second file.
I have a constructor :



public class Lanceur { 
constructor(angleAiguille) {
this.angleAiguille = angleAiguille;
} // And functions .....


I have this line in my first file : lanceur = new Lanceur(0);



And I call my files in a HTML files with <script src="js/canvas.js" type="text/javascript"></script>, for example.










share|improve this question















I am trying to use a JS function which is in an another JS file and I have this error :




ReferenceError: Lanceur is not defined




Lanceur is my object which is defined in my second file.
I have a constructor :



public class Lanceur { 
constructor(angleAiguille) {
this.angleAiguille = angleAiguille;
} // And functions .....


I have this line in my first file : lanceur = new Lanceur(0);



And I call my files in a HTML files with <script src="js/canvas.js" type="text/javascript"></script>, for example.







javascript file class canvas referenceerror






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 15:18









George

4,34311731




4,34311731










asked Nov 21 at 15:17









Vincent Bourdon

81




81








  • 2




    You need to load the class before making an instance from it. So if the class is in the second file and the new Lanceur() call in the first, you need to swap the files around.
    – Shilly
    Nov 21 at 15:20






  • 1




    Are you compiling this with something? Your use of public confuses me, are you sure you don't mean class Lanceur { }?
    – James Ives
    Nov 21 at 15:22












  • Thank you Shilly and James. Now, how I call my functions ?
    – Vincent Bourdon
    Nov 21 at 15:25
















  • 2




    You need to load the class before making an instance from it. So if the class is in the second file and the new Lanceur() call in the first, you need to swap the files around.
    – Shilly
    Nov 21 at 15:20






  • 1




    Are you compiling this with something? Your use of public confuses me, are you sure you don't mean class Lanceur { }?
    – James Ives
    Nov 21 at 15:22












  • Thank you Shilly and James. Now, how I call my functions ?
    – Vincent Bourdon
    Nov 21 at 15:25










2




2




You need to load the class before making an instance from it. So if the class is in the second file and the new Lanceur() call in the first, you need to swap the files around.
– Shilly
Nov 21 at 15:20




You need to load the class before making an instance from it. So if the class is in the second file and the new Lanceur() call in the first, you need to swap the files around.
– Shilly
Nov 21 at 15:20




1




1




Are you compiling this with something? Your use of public confuses me, are you sure you don't mean class Lanceur { }?
– James Ives
Nov 21 at 15:22






Are you compiling this with something? Your use of public confuses me, are you sure you don't mean class Lanceur { }?
– James Ives
Nov 21 at 15:22














Thank you Shilly and James. Now, how I call my functions ?
– Vincent Bourdon
Nov 21 at 15:25






Thank you Shilly and James. Now, how I call my functions ?
– Vincent Bourdon
Nov 21 at 15:25














1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










You need to create the class before you can create an instance of it. You also don't need the keyword public as browsers don't support it currently (Unless you're compiling this through Babel or something similar, but that wasn't obvious from your post).



In your first file include the code that makes up the class, I've added a method as an example.



class Lanceur { 
constructor(angleAiguille) {
this.angleAiguille = angleAiguille;
}

someMethod() {
console.log('Firing')
}
}


You can then create an instance of it like so in your second file and call its methods.



const instance = new Lanceur;


// Calling a method...
instance.someMethod();


You can learn more about JavaScript class constructors here.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415166%2freferenceerror-is-not-defined%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    You need to create the class before you can create an instance of it. You also don't need the keyword public as browsers don't support it currently (Unless you're compiling this through Babel or something similar, but that wasn't obvious from your post).



    In your first file include the code that makes up the class, I've added a method as an example.



    class Lanceur { 
    constructor(angleAiguille) {
    this.angleAiguille = angleAiguille;
    }

    someMethod() {
    console.log('Firing')
    }
    }


    You can then create an instance of it like so in your second file and call its methods.



    const instance = new Lanceur;


    // Calling a method...
    instance.someMethod();


    You can learn more about JavaScript class constructors here.






    share|improve this answer



























      up vote
      0
      down vote



      accepted










      You need to create the class before you can create an instance of it. You also don't need the keyword public as browsers don't support it currently (Unless you're compiling this through Babel or something similar, but that wasn't obvious from your post).



      In your first file include the code that makes up the class, I've added a method as an example.



      class Lanceur { 
      constructor(angleAiguille) {
      this.angleAiguille = angleAiguille;
      }

      someMethod() {
      console.log('Firing')
      }
      }


      You can then create an instance of it like so in your second file and call its methods.



      const instance = new Lanceur;


      // Calling a method...
      instance.someMethod();


      You can learn more about JavaScript class constructors here.






      share|improve this answer

























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        You need to create the class before you can create an instance of it. You also don't need the keyword public as browsers don't support it currently (Unless you're compiling this through Babel or something similar, but that wasn't obvious from your post).



        In your first file include the code that makes up the class, I've added a method as an example.



        class Lanceur { 
        constructor(angleAiguille) {
        this.angleAiguille = angleAiguille;
        }

        someMethod() {
        console.log('Firing')
        }
        }


        You can then create an instance of it like so in your second file and call its methods.



        const instance = new Lanceur;


        // Calling a method...
        instance.someMethod();


        You can learn more about JavaScript class constructors here.






        share|improve this answer














        You need to create the class before you can create an instance of it. You also don't need the keyword public as browsers don't support it currently (Unless you're compiling this through Babel or something similar, but that wasn't obvious from your post).



        In your first file include the code that makes up the class, I've added a method as an example.



        class Lanceur { 
        constructor(angleAiguille) {
        this.angleAiguille = angleAiguille;
        }

        someMethod() {
        console.log('Firing')
        }
        }


        You can then create an instance of it like so in your second file and call its methods.



        const instance = new Lanceur;


        // Calling a method...
        instance.someMethod();


        You can learn more about JavaScript class constructors here.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 21 at 15:35

























        answered Nov 21 at 15:30









        James Ives

        1,3061332




        1,3061332






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415166%2freferenceerror-is-not-defined%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Lallio

            Futebolista

            Jornalista