1. Point the Prototype (prototype) to the object (inheritance)
var Student = { ' Robot ', 1.2, function () { Console.log ( this. Name + ' is running ... ');} ; var xiaoming = { ' xiaoming '= Student; // for demonstration purposes only. Generally do not use obj.__proto__ directly to change the prototype of an object
2. The Object.create()
method can pass in a prototype object and create a new object based on that prototype, but none of the properties of the new object
//prototype objects:varStudent ={name:' Robot ', Height:1.2, run:function() {Console.log ( This. Name + ' is running ... '); }};functioncreatestudent (name) {//Create a new object based on the student prototype: vars =object.create (Student); //Initialize the new object:S.name =name; The Name property of the//s is assigned the new name parameter returns;}varXiaoming = Createstudent (' Xiao Ming '); Xiaoming.run (); //Xiao Ming is running ...xiaoming.__proto__ = = = Student;//true
JavaScript full Learning (object)