Reputation: 711
I have created a class in javascript, and I want to have methods as member of that class with parameter. How can we do? I have done following code in order to create a class and methods -
function Classname(){
a1 = 100;
this.a2 = 0;
}
Classname.prototype.method1 = function (message) {
alert(message);
};
//Creating object
var obj1 = new Classname();
But when I am calling the method as -
obj1.method1("Hello");
Then I am getting error that Uncaught ReferenceError: messgae is not defined
.
Upvotes: 1
Views: 5107
Reputation: 29424
Uncaught ReferenceError: messgae is not defined
Are you sure that you use exactly the same code in your environment as you provided in the question?
You obviously use a name which can't be resolved due to a typo in the name (messgae
→ message
).
Upvotes: 1
Reputation: 129792
Your code works. Is it a verbatim copy?
Your error message seems to reference a misspelled variable, messgae
.
Upvotes: 1