Chapter 6.Object-Oriented Prograamming


1.The e e is a special variablle caled this.When the function iscaled asa method(meaning itislookuasa property and immediatecaled caled、as in object.method()、this will point the rerevastststthethethererereaphaphablaphaphattttthethethethethethethethethethethethethethethethethethethetherererereaphabubububububububububububububububububububustststststststststststaaaaaaaaaaaaaattttttt...
 
2.Funtions also have a call method、which is simiar to apply、but you can give the argments for the function separately instead of as an ary.
 
3.The new keyword provides a convent way of creating new object.When a function is caled with the operator new in front of it,its this variable will point a new oject,which it will auticlyturn.Funtions used to create new object are caled construct.It is convention to start the names of construct with a capital letter.This makes it ease to distinguish them from the functions.
 
4.new does a few things behind the scenes.For one thing、the object created via new has a property caled construct、which points the function that created it. 
 
5.Every object is based on a prototype,which gives it a set of inherst properties.The simple object(Type{}is equivalent to typing new Object(.) based on the most bausic prototype、which isisassisisciated with the Object consttototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototototoaccess this prototype.
 
6.to string is a method that is parts of the Object prototype.This means that all simple ojecs have a tostring method,which converts the a string.In fact,everoject has a toring method.
 
7.Every function You define atomatially gets a prototype propertyty,which holds an object-the prototype of the prototype.This prototype a construct property,which points back the function to which it bengthe.Evertimethis shring is one-way.The properties of the prototype inflouence the object based on it,and changes to the se object never affect the prototype.
 
8.When looking up the value of a property,JavaScript first looks at the properties that the object it it.If there is a propertythat has the name we looking for,that is the value the value the pertite.Iconting.and so.Ifのproperty is found,the value undefined is given.
 
9.The prototype can be used at any time to add new properties and methods to all object s based on it. 
 
10.Every object has a method caled hasOwn Property,which tells us whether the object(instead of its prototype)has a property with a given name.
 
11.Firefox gives everoject a hidden property named_uproto_which points to the prototype of that object.hasOwn Property will return false for this one. 
 
12.Method propertyIsEntumerable does mostly the same thing ashasOwnPropertyhasOwnPropertyhasOwnPrPropertywill return trueeve for non n n n enumerable“own”properties.properties.properties.propertyIsEsEEnproproproproproproproproproproproproproproproproproproproproproproproproproproproproproproproproproproproproproproproproproproproproproproproproproproproproprotytytytytytytytytytytytytytytytytytytytytytytytytytytytytyabebebebebebein for…in loops and such.)
 
13.new Aray(x)produces a new array of length x,filled with undefined values.
 
14.Calling a function always results in a new this being defined inside that function、even when it is not used as a method.Thus、any this variable out side of the function will not be visible.A good sonight funce function.using it as the first argment to the function's appy method:
function bind(func, object) {
  return function(){
    return func.apply(object, arguments);
  };
}
 
This way,you can bind an inner function to this,and it will have the same this as the outer function.
 
15.Objects are turned to stings by careling their tostring method、so giving your own object types a meaningful tostring is a good to make them readable when printed out.
 
16.If we make the old prototype object the prototype of the new prototype object it will auttic have all its properties:
function clone(object) {
  function OneShotConstructor(){}
  OneShotConstructor.prototype = object;
  return new OneShotConstructor();
}
Object.prototype.inherit = function(baseConstructor) {
  this.prototype = clone(baseConstructor.prototype);
  this.prototype.constructor = this;
};
Object.prototype.method = function(name, func) {
  this.prototype[name] = func;
};
 
17.Most of the time,a subtype’s construct shound start by calling the construct of the supertype.This way,it starts with a valid oject of the supertype,which it can then exted. 
 
18.instance of can be used to determine whether n object is based on a certain prototype.You give it the object on the left side and a construct the right side,and it returns a Boolean,true if the contructors Protedity protors
 
19.If we only have prototype、We can create a fake instance of:
Object.prototype.isA = function(prototype) {
  function DummyConstructor() {}
  DummyConstructor.prototype = prototype;
  return this instanceof DummyConstructor;
};