Watch.JS icon indicating copy to clipboard operation
Watch.JS copied to clipboard

Assign object property to a jQuery object

Open zzarcon opened this issue 12 years ago • 4 comments

When i do this:

var obj = {
   element: $('#myDiv')
};

watch(object, function(prop, action, newvalue, oldvalue) {
        console.log(prop, action, newvalue,oldvalue,this);
});

Throws a error: TypeError: obj.watchers[prop].push is not a function

watch.js (line 258)

obj.watchers[prop].push(watcher); //add the new watcher in the watchers array

zzarcon avatar May 22 '13 12:05 zzarcon

Hi, I understand your concern but the best I can do is check if it is a jQuery Object and throw an specific exception telling that you should observe only your own objects.

jQuery objects are huge and with a lot of cyclic references. The idea of Watch.JS is to use in your own objects. I think you should use the jquery event features.

melanke avatar Jun 03 '13 15:06 melanke

A good idea is to create another project: a jQuery plugin to adapt jQuery objects to Watch.JS

melanke avatar Jun 03 '13 15:06 melanke

See please http://jsfiddle.net/KwQbc/16/ the same situation when the we watching object Array and push it to the object and the object set changes

ale4ko avatar Sep 11 '13 14:09 ale4ko

I think now you are asking too much HAHAHA I dont know if we could watch an array directly, I will think about it, analyse the code and let you know

but thanks for reporting this

melanke avatar Sep 11 '13 14:09 melanke