Is it possible to listen for changes to an object's attributes in JavaScript?

后端 未结 7 1679
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-02 23:37

I\'m working on a fiddly web interface which is mostly built with JavaScript. Its basically one (very) large form with many sections. Each section is built based on options

7条回答
  •  無奈伤痛
    2020-12-03 00:16

    jQuery is just amazing. Although you could take a look to ASP.NET AJAX Preview.

    Some features are just .js files, no dependency with .NET. May be you could find usefull the observer pattern implementation.

    var o = { foo: "Change this string" };
    
    Sys.Observer.observe(o);
    
    o.add_propertyChanged(function(sender, args) {
        var name = args.get_propertyName();
        alert("Property '" + name + "' was changed to '" + sender[name] + "'.");
    });
    
    o.setValue("foo", "New string value.");
    

    Also, Client Side templates are ready to use for some interesting scenarios.

    A final note, this is fully compatible with jQuery (not problem with $)

    Links: Home page, Version I currently use

提交回复
热议问题