melanke / Watch.JS

watch the changes of any object or attribute
Other
2.14k stars 219 forks source link

Pushing values into array #36

Closed CodersBrothers closed 11 years ago

CodersBrothers commented 11 years ago

Its awfull that cannot do something like this var a = []; watch(a, function(){ console.log('Something'); }); a.push('hi');

But its really awfull when you put something like: var a = { b:[ { id: 1, name: 'qqqqqqqqqqqq' }, { id: 2, name: 'rrrrrrrrrrr' } ] }; watch(a, function(){ console.log('Something'); }); console.log(a.b);

¿Where is the values?

I changed to use this library, maybe author can get ideas: https://github.com/jdarling/Object.observe

melanke commented 11 years ago

your variable "a" need to be associated to a parent object it is impossible to do such a thing even with this other library

this will work:

    var obj = {
        a: []
    }
    watch(obj, "a", function(){
        console.log('Something');
    });
    obj.a.push('hi');