Home >Web Front-end >JS Tutorial >JavaScript object-oriented definition member method instance analysis_javascript skills

JavaScript object-oriented definition member method instance analysis_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:20:251139browse

This article analyzes object-oriented definition member methods in JavaScript with examples. Share it with everyone for your reference. The details are as follows:

Javascript is object-oriented and defines member methods as follows:

Copy code The code is as follows:

Description:
(1) The constructor is used here;
(2) The definition method of this.show=function() makes every instantiated object have this method. If you need to own an instantiated object separately, you can write the function externally and then pass it over, as in the example below;
(3) There can also be parameters in function() of this.show.

Function defined externally
Because the properties and methods of JavaScript objects are dynamically added, they can be defined like this:

Copy code The code is as follows:

Or it can be defined like this:
Copy code The code is as follows:
p1.show1 = function show(){... .............}

I hope this article will be helpful to everyone’s JavaScript programming design.

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