Skip to content

Latest commit

 

History

History
123 lines (102 loc) · 2.06 KB

File metadata and controls

123 lines (102 loc) · 2.06 KB

Objects

Dot Notation

Use dot notation whenever possible. Even if it causes some inconsistency, it is preferred to use dot notation combined with bracket notation than using only bracket notation

Good

ENV.cloudinary = {
  apiKey: "abc123"
};

ENV["ember-simple-auth"] = {
  authenticator: "application"
}

Bad

ENV["cloudinary"] = {
  apiKey: "abc123"
};

ENV["ember-simple-auth"] = {
  authenticator: "application"
}

Destructuring

Use object destructuring whenever possible in both variable assignment and object creation

Good

// Assignment
let { name, age, location } = user;

// Object creation
let name = "Anonymous kohactivator";
let age = 30.6;
let location = "Chicago, IL";

let user = { name, age, location };

Bad

// Assignment
let name = user.name;
let age = user.age;
let location = user.location;

// Object creation
let user = {
  name: "Anonymouse kohactivator",
  ago: 30.6,
  location: "Chicago, IL"
}

// Object creation (very bad)
let name = "Anonymous kohactivator";
let age = 30.6;
let location = "Chicago, IL";

let user = {
  name: name,
  age: age,
  location: location
}

No Trailing ("Dangling") Commas

The last property in an object should not have a trailing comma

Good

let dog = {
  goodBoy: true,
  likesCats: false
};

Bad

let dog = {
  goodBoy: true,
  likesCats: false,
};

Property Spacing

One-line properties can be stacked without any padding, but it is recommended to pad functions and other multiline properties with a single empty line

Good

let dog = {
  goodBoy: true,
  likesCats: false,

  goForAWalk(length) {
    return walks({ length });
  },

  goForARide() {
    return rolls();
  }
};

Bad

let dog = {
  goodBoy: true,
  likesCats: false,
  goForAWalk(length) {
    return walks({ length });
  },
  goInTheCar() {
    return rolls();
  }
};