Home >Web Front-end >JS Tutorial >A good introduction to object-oriented JavaScript, page 1/2_js object-oriented
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 "