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中文网
PHP中文网Original
2016-05-16 19:03:071031browse

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 "

Statement:
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