Home >Web Front-end >JS Tutorial >JavaScript uses prototype to define object types_prototype

JavaScript uses prototype to define object types_prototype

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 19:19:30799browse

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






Statement:
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