onlycode.org

javascript
jquery
html
css
angularjs
node.js
ajax
html5
php
json
arrays
google-chrome
dom
regex
reactjs
ecmascript-6
javascript-events

your's history:
accessing an object39 s...

Accessing an object's property from an event listener call in Javascript, just only code

event-handling | javascript-events | events | javascript

edit
var someObj = function someObj(){
    this.prop = 33;
    var self = this;
    this.mouseMoving = function() { console.log(self.prop);}

    document.getElementById("someDiv").addEventListener('mousemove', this.mouseMoving, true);
}

30
Matthew Crumley, 04.07.2009 07:44




edit
var someObj = function someObj(){
       this.prop = 33;
        this.mouseMoving = function() { console.log(this.prop);}

        document.getElementById("someDiv").addEventListener('mousemove', this.mouseMoving.bind(this),true);

 }
console.log(this.referenceToObject.prop); //this references the DOM element in an event.

29
Itay Moav -Malimovka, 04.07.2009 07:44



edit
function someObj() {
  var me = this;
  this.prop = 33;

  this.mouseMoving = function() {
    alert(me.prop);
  }

  document.getElementById("someDiv").addEventListener('mousemove', this.mouseMoving, true);
}

11
alexbuzzbee, 01.07.2014 18:16




edit
function someObj (){
    var self = this;
    this.prop = 33;
    this.mouseMoving = function() { alert(self.prop);} // You access the current
                                                       // instance, stored in *self*
                                                       // since *this*, inside the 
                                                       // function, is in another 
                                                       // context.
    //...
}

var mySomeObj = new someObj(); // Object instantiation
function someObj (){
    var prop = 33;
    this.mouseMoving = function() { alert(prop);} 

    //...
}
var mySomeObj = new someObj(); // Object instantiation

10
CMS, 04.07.2009 08:03

Add your just only code

your name:    



If you need full text click here

Some similar links Accessing an object's property from an event listener call in Javascript ↓:
Why FF says that window.event is undefined? (call function with added event listener)

Listener for property value changes in a javascript object

Scroll event listener javascript

How can I temporarily disable the onclick event listener after the event has been fired?



This project is created for those who just need only code, wihout maaaaaaaaaaany words.