Objects/keys on the right override those to the left
{...x,...y,...z, a:1}Object.assign(x, y, z) //
Copy
{...x}Object.assign({}, x)
Delete
deletemyObject.prop;
Equality
=== will do ptr equality
Use lodash .isEqual for deep equality
Old Classes
functionPerson(name) {this.name = name;this.greeting=function() {alert('Hi! I\'m '+this.name +'.'); };}var person1 =newPerson('Bob'); //new returns objvar person2 =newPerson('John'); //contains a new definition of gretting
To define functions out of scope,
functionTest(a, b, c, d) {// property definitions}// First method definitionTest.prototype.x=function() { ... };// Second method definitionTest.prototype.y=function() { ... };
Can always add new values
person1.newv ="secretsss";
Prototypes?
objects can have a prototype object that all instances inherit from, everyone inherits from object prototype
Person.prototypeObject.prototype
Changes to prototype affect all people
Person.prototype.farewell=function() {alert(this.name.first +' has left. Bye for now!');};person1.farewell();
Create
Object.create makes a new object with the object given as its prototype, basically defining a subclass
var person3 =Object.create(person1);//copy constructor, (inherit from person1)
Inheritance
Its a mess, stupid javascript didn't want to do this
functionTeacher(first, last, age, gender, interests, subject) {Teacher.prototype=Object.create(Person.prototype); //inherit from Person.prototypeTeacher.prototype.constructor= Teacher; //you just replaced the constructor, add it backPerson.call(this, first, last, age, gender, interests); //.call allows you to pass this setting itthis.subject = subject;}