0

I have a Javascript Object with some properties, for example, Clipboard. here my custom object:

MyApp.sessionState

and this is the getProprieties (returns a String)

MyApp.sessionState.getProperty("clipboard");

This input return for example "this is text". There is same way to append an eventListener "change" on this Object or this string? I tried this but it doesn't work:

var a = MyApp.sessionState
a.addEventListener("change", function(){console.info("change!")}, false);

but returns:

TypeError: Object # has no method
'addEventListener'

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
r1si
  • 1,136
  • 2
  • 19
  • 34
  • 2
    You can't addEventListeners to Objects, it needs to be a DOM element. – Todd Motto Jan 17 '14 at 14:30
  • http://stackoverflow.com/search?q=javascript+listen+for+changes+to+object – cookie monster Jan 17 '14 at 14:30
  • 1
    possible duplicate of [javascript event listener for changes in an object variable](http://stackoverflow.com/questions/5860218/javascript-event-listener-for-changes-in-an-object-variable) – cookie monster Jan 17 '14 at 14:31
  • you can attach events listeners to plain-old JavaScript objects. You would need to manually implement the observer pattern to support that functionality – ppoliani Jan 17 '14 at 14:33
  • Can you show us your implementation of `MyApp.sessionState`, please? – Bergi Jan 17 '14 at 16:09

0 Answers0