Home > Web Front-end > JS Tutorial > body text

Defining object categories in Javascript_javascript tips

WBOY
Release: 2016-05-16 19:22:43
Original
1009 people have browsed it

From: JavaEye.com

Pay attention to the definition of object categories in JavaScript, use function to define object categories, and initialize objects using the new operator
function Person(name, age) {
this.name = name;
this.age = age;
this.toString = function() {
document.writeln("[name]:" this.name "
" "[age]:" this .age);
}
}

Complete simple HTML



JavaScript






<script> <BR>function Person(name, age) { <BR> this.name = name; <BR> this.age = age; <BR> this.toString = function() { <BR> document.writeln("[name]:"+this.name+"<br>"+"[age]:"+this.age); <BR> } <BR>} <BR></script><script> <BR> var person = new Person(); <BR> person.name="robbin"; <BR> person.age=30; <BR> person.toString(); <BR></script>
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