1

I recently came to know this function Object.observe() and tried implementing in my app.

var cs = {
    name : "java",
    version : "1.0"
}

cs.name = "javascript";
function doThis(){
    console.log(cs.name);
}
Object.observe(cs, doThis);

But I see the above mentioned error.

TypeError: Object function Object() { [native code] } has no method 'observe'

Can some one throw some light on what am I missing here.

Bergi
  • 513,640
  • 108
  • 821
  • 1,164
javaMan
  • 5,562
  • 17
  • 57
  • 86
  • 2
    Object.observe is a very new function. What browser/version are you experiencing problems in? – Hacknightly Oct 22 '13 at 17:20
  • Google Chrome Version 30.0.1599.101 m ( It says upto date) – javaMan Oct 22 '13 at 17:23
  • 1
    Perhaps try enabling experimental javascript by following the first few steps in this article http://updates.html5rocks.com/2012/11/Respond-to-change-with-Object-observe – Hacknightly Oct 22 '13 at 17:23

1 Answers1

3

If I'm not mistaken it only exists in google canary at the moment, it is an extremely new JS prototype.

You are getting this error because the browser you are using does not have it implemented.

Mark Pieszak - Trilon.io
  • 44,537
  • 13
  • 74
  • 89