Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between this.set and Ember.set

Tags:

ember.js

Is there any difference between following two conditions this.set('firstName','ember') and Ember.set(this,'firstName','ember')

like image 421
Kumar Avatar asked Mar 09 '23 09:03

Kumar


1 Answers

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()

like image 140
bsegraves Avatar answered Apr 03 '23 19:04

bsegraves