Is there any difference between following two conditions this.set('firstName','ember') and Ember.set(this,'firstName','ember')
Ember's computed property chain and observers rely on you calling object.set() on the object in question. You will often see warnings to this effect if you forget.
However, it's possible to get into a situation where you may not know if the object you've been handed is an Ember.Object or just a plain javascript object. That's where Ember.set()
comes in handy - it works on both types of objects.
const setFoo(target, value) {
Ember.set(target, 'foo', value);
}
const a = {foo:null};
const b = Ember.Object.create({foo:null});
// both calls are valid because we use Ember.set()
setFoo(a, 'johnny');
setFoo(b, 'bravo');
Here's the official documation that's kinda helpful: Ember.set()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With