JS function Understanding

Source: Internet
Author: User

The JS function is more than just a function, because the uniqueness of its data structure, the function can be a property function or a class

---a property

---a function

---of a class


Draw:function (obj, time) {}

Draw is a property of an object that can be called using the method of Obj.draw (obj, time)


A single case in JS

This object represents a singleton, a single instance, and cannot create a repeating instance.

var car = {

Color: ' Red ',

Draw:function () ={

Alert (' Red Car '); }



The class in JS is approximate to class

(2) Objects of "class" meaning

Indicates that this is a type, at which time the car is created by a constructor of new and each instance is allocated a separate memory space.

function Car (color) {


This.draw=function () {

alert (This.color); }


Use: var car1 = new Car (' Red '); Car1.color= ' Blue '; Car1.draw ();


JS function Understanding

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.