OT: I keep trying to get into backbone but I just get driven crazy by `get` and `set`. Inspecting your object feels like a world of pain, which is no fun when I'm playing with code. And it also makes it feel like you're not programming js any more. Quite a few years back an old company I used to work for had a similar framework and perhaps it's just latent hatred for that rather annoying framework. I know it's a limi…
> perhaps it's just latent hatred for that rather annoying framework ... hopefully ;) The reason why you need `set` is so that you know when to trigger `change` events. Getters and setters aren't going to fly if you need to support Internet Explorer. One alternative is the Angular.js tradeoff, where you're setting regular properties on vanilla objects and arrays ... but then Angular is going in behind the scenes and…
And it also gets rid of the need to hide all your properties in an attributes collection. I'm not sure why you think that's good because it doesn't fire events.
And if you really need ignore properties, you could do something like this:
var Person = {};
Person.prototype = new Model;
var bill = Person.create({ name : "Bill", email : "bill@example.com" }); //adds all using defineProperty and a watcher in get, set functions
alert(bill.name); //Woo, alerts "Bill", not undefined!
bill.name = "Bob"; //event fires
person.special = "blah"; //wouldn't be watched as it's been added after creation
person.addProperty("special2", "blah2"); //would be watched
person.special2 = "blah3"; //events now fire with 'normal' access
var person2 = Person.create({ name : "Bill", email : "bill@example.com", special : "thing" }, { ignore : ["special"]}); //special is not watched
You could even do the opposite and tell it exactly which properties to even bother watching.There's a reason getters and setters have been added to js, and it's for exactly this kind of thing!