JavaScript full Learning (object)

Source: Internet
Author: User
Tags ming

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.