Hanshunping JavaScript Instructional Video _ Learn notes 18_js Super Mario games 2_js Object-oriented further instructions __JS

Source: Internet
Author: User
Question: How to get the content of CSS directly
Give a few examples to test first: first define a CSS file
#div2 {
	width:500px;
	height:200px;
	Background-color:green;
	left:50px; top:200px; Position:absolute;
}
 
#div3 {
	width:500px;
	height:200px;
	background-color:red;
	left:50px; top:450px; Position:absolute;
}

Define an HTML file again
 

Through the above code test, found that you can not directly get the attributes in the CSS, the problem first put JS-oriented (based on) object programming----construction Method (function) Introduction to construction methods (functions)
Basic usage of constructors
function class name (argument list) {
   property = parameter value;
}

Examples are as follows:
 

Extension: Can pass directly to an object a function.
Please see the following question:
When you initialize a property value to an object, you can also specify the function property
See Case:
 

Construct method (function) Summary constructor method name and class name the same primary role is to complete initialization of a new object instance when an object instance is created, the system automatically invokes the method of constructing the object
Here we further refine the definition of the class:
further understanding of object-oriented programming
create another form of an object:If an object is simpler, we can create it directly (you can specify normal properties and function properties)
 

Sometimes we see such a calling method
The name of the function. Call (object instance)

So called, the function's this is pointing to an object instance
 


Use for ... in to easily view all properties and methods of an object
 

The most important thing here is the properties and methods of the browser window object, using for in We can know which methods and properties in the Browser Support window object We are currently using, so we don't have to look up the network, there are other objects in the browser in addition to Window objects, as shown in the following illustration:


View the properties and methods of the browser window object in the following ways: (I use Firefox browser)
Loops list all properties and methods of the Window object
Document.writeln ("* * * Current browser Window object has properties and methods ***<br/>");
for (var key in window) {
		Document.writeln (key + ":" + Window[key] + "<br/>");
}

Output results:

Then look at the browser history object properties and methods: (I use the Firefox browser)
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.