I have an unfortunate scenario where I must translate attribute names
(coming from a server response) prior to initialization on a Map or
Model instance.
I settled on this solution below. It works as far I can tell, but I
wanted a gut-check on any unforeseen caveats this may present. I had
also considered using the "define: {}" form of constructing
attributes and simply aliasing all of the attribute names that needed
to change, but that seemed ugly and wasteful.
- var SomeModel = can.Map.extend({
- setup: function (attrs) {
- return this._super(translatorFn(attrs, newAttrKeys));
- }
- });
- var model = new SomeModel({ extraLongVerboseName: 'Foo' });
- model.attr(); // => { shortName: 'Foo' }