I want to have a prototype and call a static function. Here is my code:
function Client() {
this.username = "username",
this.password = "Password",
this.printUsername = function() {
this.username=$("#Username").val()
console.log(this.username);
};
};
Here is me calling it:
<button onclick="Client.printUsername()" type="button">Submit</button>
Here is the error in the console:
Uncaught TypeError: Object function Client() {
this.username = "username",
this.password = "Password",
this.printUsername = function() {
this.username=$("#Username").val()
console.log(this.username);
};
} has no method 'printUsername'
What is wrong with my code?
This still creates the error:
function Client() {
this.username = "username",
this.password = "Password",
this.setUsername = function() {
this.username=$("#Username").val()
console.log(this.username);
};
};
Client.prototype.printUsername = function() {
this.username = $("#Username").val();
console.log(this.username);
}