Polymorphic
The idea behind polymorphism is to separate "what to do" and "who to do and how to do", that is, to separate "unchanging things" from "mutable things".
The most fundamental function is to eliminate these conditional branching statements by translating the conditional branching statements into the polymorphism of the objects.
Packaging
The goal is to hide information.
Encapsulating data:
JS depends on the scope of the variable to implement the encapsulation feature, and can only simulate the public and private properties of the two
var MyObject = (function () {var _name = "Salody"; Private variable return {getname:function () { //public method return _name;}}) (); Console.log (Myobject.getname ()); Output: Salodyconsole.log (myobject._name); Output: undefined
Prototype mode
From the point of view of design patterns, a prototype pattern is a pattern used to create an object, and if we want to create an object, one way is to specify its type first, and then create the object through the class. Prototype mode Choose another way, we don't care about the specific type of object, we find an object, and then we create an identical object by cloning .
A object.create method is provided in ECMASCRIPT5 that can be used to clone an object
The real purpose of prototype mode is to provide a convenient way to create objects of a certain type, and cloning is just the process and means of creating this object.
1 varPlane =function () {2 This. Blood = 100;3 This. Attacklevel = 1;4 This. Defencelevel = 1;5 }6 7 varPlane =NewPlane ();8Plane.blood = 500;9Plane.attacklevel = 10;TenPlane.defencelevel = 3; One A varCloneplane =object.create (plane); - Console.log (cloneplane); - the //for browsers that do not support the Object.create method, use the following code -Object.create = Object.create | |function(obj) { - varF =function () {}; -F.prototype =obj; + - return NewF (); +}
Object-oriented JavaScript