Created
April 25, 2013 11:12
-
-
Save InFog/5459018 to your computer and use it in GitHub Desktop.
Exemplo de OO em JS usando uma função. Existe uma associação de evento para definir o nome de p1.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var MyClass = function () { | |
this.name = ""; | |
this.setName = function (name) { | |
this.name = name; // Este this é o MyClass, não a function atual | |
}; | |
this.getName = function () { | |
return this.name; | |
}; | |
this.keyPressSetter = function (k) { | |
this.name = this.name + String.fromCharCode(k.keyCode); | |
console.log(this.name); | |
}; | |
}; | |
p1 = new MyClass(); | |
p2 = new MyClass(); | |
p2.setName("Jack"); | |
document.getElementById('myText').onkeyup = function (k) { | |
p1.keyPressSetter(k); | |
}; | |
console.log(p2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment