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.
javascript file class canvas referenceerror
add a comment |
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.
javascript file class canvas referenceerror
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 ofpublicconfuses me, are you sure you don't meanclass 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
add a comment |
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.
javascript file class canvas referenceerror
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
javascript file class canvas referenceerror
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 ofpublicconfuses me, are you sure you don't meanclass 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
add a comment |
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 ofpublicconfuses me, are you sure you don't meanclass 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
add a comment |
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.
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
edited Nov 21 at 15:35
answered Nov 21 at 15:30
James Ives
1,3061332
1,3061332
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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
publicconfuses me, are you sure you don't meanclass 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