Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inspect Ember.js: Get the type of an object (Class)?

Tags:

ember.js

I use console.log() a lot, especially in combination with Ember.inspect(). But there's one thing I miss:

How can I find out the type of an object (Class)?

For example: Getting something like <Sandbox.ApplicationController:ember288> when inspecting Ember.get("controller")?

like image 394
kraftwer1 Avatar asked Nov 04 '12 16:11

kraftwer1


People also ask

Is Ember an object?

Introducing: Ember Objects The Ember Object class extends plain JavaScript objects to provide core framework functions such as participating in Ember's binding system or how changes to an object automatically trigger updates to the user interface.

How to create a object in Ember?

create (arguments) public Accepts either no arguments, or an object containing values to initialize the newly instantiated object with. import EmberObject from '@ember/object'; const Person = EmberObject. extend({ helloWorld() { alert(`Hi, my name is ${this. get('name')}`); } }); let tom = Person.

How do I create a class in Ember?

To define a new Ember class, call the extend() method on Ember. Object : App. Person = Ember.

How does Ember JS work?

Ember uses templates to organize the layout of HTML in an application. Ember templates use the syntax of Handlebars templates. Anything that is valid Handlebars syntax is valid Ember syntax. Here, {{name}} is a property provided by the template's context.


1 Answers

If you just want the model name (for example app/models/comment.js has the model name comment), you can use thing.constructor.modelName.

For example:

var aComment = this.get('store').createRecord('comment'); aComment.get('constructor.modelName') // => 'comment' 
like image 167
Kerrick Avatar answered Sep 25 '22 17:09

Kerrick