JS: The Secret Life of Objects

Home > Preview

The flashcards below were created by user jasminep16 on FreezingBlue Flashcards.

  1. An object
    Is a hard shell that hides the gooey complexity inside it and instead offers us a few knobs and connectors (such as methods) that present an interface
  2. Encapsulation
    • The idea that the data of an object should not be directly exposed. Instead, callers that want to achieve a given result are coaxed into
    • proper usage by invoking methods rather than accessing the data directly.
  3. Methods
    • Are simply properties that hold functions.
    • var rabbit = {};
    • rabbit.speak = function(line) {
    • console.log("The rabbit says" + line + "'");
    • };
  4. method call()
    A different this object can be assigned when calling an existing function. this refers to the current object, the calling object. Accepts an argument list.
  5. prototype
    A prototype is another object that is used as a fallback source of properties
  6. Constructors
    In JavaScript, calling a function with the new keyword in front of it causes it to be treated as a constructor. A more convenient way to create objects that derive from some shared prototype is to use a constructor. Constructors should be capitalize
  7. new
    An object created with the new is said to be an instance of its constructor
  8. prototype interference
    A prototype can be used at any time to add new properties and methods to all objects based on it.
  9. enumerable properties
    All properties that we create by simply assigning to them are enumberable
  10. hasOwnProperty method
    This method tells us whether the object itself has the property, without looking at its prototypes. This is often a more useful piece of information than what the in operator gives us.
  11. non enumerable properties
    The standard properties in Object.prototype are all non enumerable. It is possible to define our own nonenumerable properties by using Object.defineProperty function, which allows us to control the type of property we are creating.
  12. Prototype-less Objects
    We can use Object.create function to create an object with a specific prototype. We are allowed to pass null as the prototype to create a fresh object with no prototype.
  13. Polymorphism
    When a piece of code is written to work with objects that have a certain interface - in this case, a toString method - any kind of object that happens to support this interface can be plugged into the code, and it will just work. Polymorphic code can work with values of different shapes, as long as they support the interface it expects.
  14. Getters and Setters
    We can specify properties that, from the outside, look like normal properties but secretly have methods associated with them. In object literal, the get and set notation allows you to specify a function to be run when the property is read or written.
  15. Object.defineProperty can be used to add a getter
    • Object.defineProperty(Textcell.prototype, "heightProp", { get: function() { return this.text.length; } });
    • When a getter but not setter is defined, writing to the property is simply ignored.
  16. Inheritance
    It allows us to build slightly different data types from existing data types with relatively little work. Typically, the new constructor will call the old constructor (using the call method in order to be able to give it the new object as its this value)
  17. The instanceOf operator
    It is occasionally useful to know whether an object was derived from a specific constructor. Binary operator - the operator will see through inherited types.

Card Set Information

JS: The Secret Life of Objects
2015-12-02 01:29:47

Chapter 6 of Eloquent Javascript: A Modern Intro to Programming
Show Answers:

What would you like to do?

Home > Flashcards > Print Preview