Home > Web Front-end > JS Tutorial > JavaScript uses prototype to define object types (conversion) [_javascript skills

JavaScript uses prototype to define object types (conversion) [_javascript skills

WBOY
Release: 2016-05-16 19:22:46
Original
1302 people have browsed it

From: JavaEye.com

prototype provides a set of JavaScript object-oriented infrastructure. We can use it for object-oriented programming. The way to define object types is as follows:

var Person = Class.create();
Person.prototype = {
initialize : function(name, age) {
this.name = name;
this.age = age;
},
toString : function() {
document.writeln("[name]:" this.name "
" "[age]:" this.age);
}
}

First use Class.create() to create an object type, and then define the object type. Note that the initialize method is the constructor of Person. The complete HTML is as follows:



< title>Test Object





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