4 ms·
Good stuff there, but unfortunately we'll have to wait a few more years for these to be usable (at least for me). Modules, block scoping, default parameter val
by rudasn 14y ago
Good stuff there, but unfortunately we'll have to wait a few more years for these to be usable (at least for me).
Modules, block scoping, default parameter values are great additions. Proxies sound good as well.
On Maps, the concept is nice but not very useful unless you can do things like
obj.get('some.deep.nested.value')
or
obj.set('some.deep.nested.value', {
'more': {
'nested': {
'stuff': 'here'
}
}
})
On Observer again the concept is absolutely great but I wonder if the changes propagate:
let obj = {
'some': {
'deep': {
'nested': {
'value': true
}
}
}
}
Object.observe(obj, function(changes){
changes.forEarch(function(change){
console.log(change);
});
});
obj.some.deep.nested.value = false
Will the observer be triggered for all changed properties (some, deep, nested, and value) or just the last one (value)?
For me Maps and Observers are highly important and it seems that no existing open source JS library/framework has implemented them in a way that makes sense.
Has anyone tried implementing these in such a way?
- doublerebel 14y agoSolutions to this problem are more common than you've found. Most recently released is Steeltoe [1], and there are previous examples (with varying features) noted in the Steeltoe reddit discussion [2]. [1] https://github.com/jclem/steeltoe https://github.com/jclem/steeltoe [2] http://www.reddit.com/r/javascript/comments/13cuxh/steeltoe_dont_shoot_yourself_in_the_foot_wjs/ http://www.reddit.com/r/javascript/comments/13cuxh/steeltoe_...
- rudasn 14y agoI remember seeing steeltoe on reddit. I like the fact that it's simple and does its job. Care to share any more?
- wycats 14y agoThe goal of the Map feature is to create a primitive to JavaScript that does not exist today and cannot be efficiently emulated. In particular, it allows the use of arbitrary, non-string keys. Objects (commonly used as Maps) can have only String keys. In contrast, desiring a way to `get` a nested String value is easily emulated in terms of current JavaScript semantics. In Ember, for example, obj.get('some.nested.path') works in all browsers because it does not require any new primitives. Observers are a similar story. `Object.observe` adds a new primitive to the language: the ability to receive asynchronous notifications about changes made to some object. On top of that, it is possible to implement semantics for nested objects and "computed properties". The Ember team has already been exploring how to incorporate Object.observe into Ember's observer system when it is more broadly available. We support observing nested paths, and the Object.observe primitive gives us enough to build what we need on top. You can expect that if certain patterns on top of these primitives become popular, TC39 will consider them in future versions of the specification.