[BUG] arrow functions with Ember.computed have this as undefined
See original GitHub issueDeclaring a computed property as
fullName: Ember.computed('firstName', 'lastName', ()=>{
return this.get('firstName') + ' ' +this.get('lastName');
})
it is transpiled into,
define('hello-world/components/a-name', ['exports', 'ember', 'hello-world/templates/components/a-name'], function (exports, Ember, layout) {
'use strict';
var _this = undefined;
exports['default'] = Ember['default'].Component.extend({
firstName: "sivakumar",
lastName: "kailasam",
fullName: Ember['default'].computed("firstName", "lastName", function () {
return this.get("firstName") + ' ' +this.get("");
})
});
});
_this = undefined
seems to be wrong to me, is this a genuine issue or am I using arrow functions in a wrong way?
//cc @stefanpenner
Issue Analytics
- State:
- Created 8 years ago
- Comments:11 (4 by maintainers)
Top Results From Across the Web
Computed property on fat arrow functions - Ember.JS
I'm just wondering why fat arrow functions don't work with computed properties. For instance: export default Ember.
Read more >Computed Properties And Arrow Functions? Not A Good Idea
As great as it sounds, arrow function expressions cannot be used in all cases. One example would be Ember computed properties.
Read more >Using arrow functions as observers fails? - ember.js
Arrow functions is a ES6 feature which is transpiled in Ember.js using Babel.js. Arrow functions is a shorter notation that also implicitly bind...
Read more >Handling common JavaScript problems - MDN Web Docs
Expand the showHeroes scope — you can see from this that the heroes variable is undefined , indicating that accessing the members property...
Read more >Cannot read property search of undefined this props location ...
Somehow (I guess because of Strict Mode) - the function always gets called twice. ... You get an error that says: 'this is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@bartocc Yes, you must use the old-style anonymous function, not the arrow functions. Arrow functions, by definition, are bound to their lexical scope and the scope cannot be changed. If you need to access
this
in your property, an arrow function simply won’t work.does this problem solved now?