Awaiting Object.observe()
to land, Remy Sharp has written his own simple implementation:
Data binding to the DOM is just one of those things that’s damn handy when you’ve got it and super laborious when you don’t. The problem is that it usually comes at a price of a hefty framework.
So, as any good re-inventer of wheels, I wrote my own two-way data binding library, partly to experiment, partly to solve existing needs in my own projects – weighing in at < 2K compressed.
The concept behind the API is fairly simple: take an object bind it to functions and/selectors given a particular mapping.
var user = Bind({
name: '[new user]',
game: { score: 0 }
}, {
'game.score': 'span.score',
name: 'input[name="username"]'
})
// usage
user.game.score += 25;