Eric
Eric

Reputation: 10658

changedTouches:TouchList is not a property?

I'm trying to understand why changedTouches is NOT an testable property of an event. For instance, if I listen to a touchstart event (via Chrome->inspect and simulate a mobile device), such as

 $(document).on('touchstart', function(event){
      console.log(event.hasOwnProperty('originalEvent')) //logs true

As expected.

Now, If I log the whole event, I can clearly see it has originalEvent.changedTouches but testing the property will fail

      console.log(event.originalEvent.hasOwnProperty('changedTouches')) //logs false

But I can list the changedTouches by doing

      console.log(event.originalEvent.changedTouches);

      /*
      logs:
      hangedTouches: TouchList(1)​​
      0: Touch { identifier: 0, screenX: 753, screenY: 746, … }​​
      length: 1
      */

Also I can test that both properties are objects

 console.log(typeof(event.originalEvent), typeof(event.originalEvent.changedTouches)); //logs object object

The question is, why can't I test this property with hasOwnProperty?

Upvotes: 0

Views: 167

Answers (1)

Braca
Braca

Reputation: 2815

From MDN:

The hasOwnProperty() method returns a boolean indicating whether the object has the specified property as its own property (as opposed to inheriting it).

try:

console.log('changedTouches' in event.originalEvent)

Upvotes: 2

Related Questions