Home > Web Front-end > JS Tutorial > How to create javaScript objects and properties_Basic knowledge

How to create javaScript objects and properties_Basic knowledge

WBOY
Release: 2016-05-16 19:20:45
Original
1158 people have browsed it
Copy code The code is as follows:

1. Create an empty object: var o = new object();
2. Create an object literal:
var cricle={x:0,y:0,radius:2}
var homer={
name:"Homer Simpson",
age :34,
married:true,
email: "zzy@163.com"
Settings and queries of 3 attributes
🎜> var book=new object();
book .title="Test";
alert(book,title);
Attribute is a new attribute of an object that is created by assigning a value to it. Although the var keyword is usually used to declare variables, it is not used to declare object properties.
Enumeration of attributes: for/in loop provides a way to traverse object attributes
function displayppName(obj)
{
var name="";
for (var name in obj)
name =name "n"
alert(name);
}

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template