Home > Web Front-end > JS Tutorial > A good introduction to object-oriented JavaScript, page 1/2_js object-oriented

A good introduction to object-oriented JavaScript, page 1/2_js object-oriented

PHP中文网
Release: 2016-05-16 19:03:07
Original
1028 people have browsed it

1) How to create an object:
1. Use constructor, for example:
var obj = new Object() // var can be omitted
var obj = new Date()

2. Use object literals, For example:

Program code

var obj = "123" // Create a String Object
var obj = /^abc$/ //Create a RegExp object


For a more complicated situation, we can directly generate a custom object with only attributes:

Program code

var obj = {
name:"killercat",
home:"www.i170.com/user/killercat"
}
document.write( obj.name "

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template