JS Deep Learning-Objects

Source: Internet
Author: User

Many articles introduce JS is a programming language, since object-oriented programming, then there must be objects, then the JS object and other object-oriented programming language object definition is different.

1.C #, an object is an instance of a class. An int type variable is an object. A struct type variable is also an object that customizes a person's type, instantiates a variable, and is also an object.

2.js object, I see the object in w3school Some introduction, for the object is always a little silly division unclear. Whether it is an instance of a type or a type, so I think for the time being directly to C #. An instance of a type is an object.

On-line Search JS Create objects way, often create objects in several ways of blogging, mainly focused on the focus.

First Kind

var clock={  Hour:12,  minute:10,  second:10,  showtime:function () {   alert (this.hour+ ":" + This.minute+ ":" +this.second);}  } Clock.showtime ();//Call


My understanding of him is to create a type that executes immediately and executes only once, returning instances of that type to clock.

So create the type first, and the instance is the object.

The second Kind

var clock = new Object (); clock.hour=12; clock.minute=10; Clock.showhour=function () {alert (clock.hour);}; Clock.showhour ();//Call


This is better understood by first creating an instance of object and then adding properties and methods to the instance.

So create the type first, and the instance is the object.

Third Kind

function Clock (hour,minute,second) {  this.hour = hour;  This.minute = minute;  This.second = second;  This.showtime = function () {   alert (this.hour+ ":" +this.minute+ ":" +this.second);}  } var newclock =new  Clock (12,12,12);  alert (Newclock.hour);
The type of a clock is defined first, and then the type is instantiated, so the object is also an instance of the type.

So create the type first, and the instance is the object.



JS Deep Learning-Objects

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.