html5 - Javascript Object print object value -
i'm trying value object , prit on screen no success...
http://jsfiddle.net/lbascg4v/5/
app.js // função construtora function keydown(e) { this.faq = e.keycode; alert(e.keycode) } // prototype com os métodos keydown.prototype = { printr: function() { alert(this.faq); } } window.addeventlistener('keydown', keydown, true); index.html <canvas id="canvas" width="300" height="300" style="border: 1px solid red"></canvas> <script> teste = new keydown(); teste.print(); </script>
when push key on canvas, want value of key , put in object, want print object , value.
the real answer question you don't need prototyping:
function keydown(){ // initialize properties this.faq = 0; this.update = function(e){ // set faq this.faq = e.keycode; } this.print = function(){ // alert faq alert(this.faq); } }
and then:
window.
test = new keydown(); addeventlistener('keydown', test.update, true); test.print(); // alert 0
Comments
Post a Comment