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

JavaScript uses prototype to define object types_prototype

WBOY
Release: 2016-05-16 19:19:30
Original
757 people have browsed it

From: JavaEye.com prototype provides a set of JavaScript object-oriented infrastructure, which we can use 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:

Copy code The code is as follows:



< meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
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