Home Web Front-end JS Tutorial Batch implementation of object-oriented example code_javascript skills

Batch implementation of object-oriented example code_javascript skills

May 16, 2016 pm 05:30 PM
inherit object-oriented

Copy code The code is as follows:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Batch implementation of object-oriented instances</title>
<script type="text/javascript ">
window.onload = function(){
function Person(name,age){
this.name = name;
this.age = age;
}
Person.prototype.showName = function(){
alert(this.name);
};
function extend(parent,child,method){
function a(){
parent .apply(this,arguments);
child.apply(this,arguments);
};
for(var i in parent.prototype){
a.prototype[i]=parent. prototype[i];
}
for(var i in method){
a.prototype[i] = method[i];
}
return a;
}; //The parameters are parent constructor, child constructor, child method
var int = extend(Person, function(name, age, job){
this.job = job;
},
{
showjob:function(){
alert(this.job);
}
}
);
var oc=new int('Xia Ke',24 ,'job');
oc.showjob();
}
</script>
</head>
<body>
<h1> for Object inheritance example</h1>
<p>Start showing examples of object-oriented implementation in batches</p>
</body>
</html>
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed explanation of C++ function inheritance: How to use 'base class pointer' and 'derived class pointer' in inheritance? Detailed explanation of C++ function inheritance: How to use 'base class pointer' and 'derived class pointer' in inheritance? May 01, 2024 pm 10:27 PM

Detailed explanation of C++ function inheritance: How to use 'base class pointer' and 'derived class pointer' in inheritance?

How do inheritance and polymorphism affect class coupling in C++? How do inheritance and polymorphism affect class coupling in C++? Jun 05, 2024 pm 02:33 PM

How do inheritance and polymorphism affect class coupling in C++?

Detailed explanation of C++ function inheritance: How to debug errors in inheritance? Detailed explanation of C++ function inheritance: How to debug errors in inheritance? May 02, 2024 am 09:54 AM

Detailed explanation of C++ function inheritance: How to debug errors in inheritance?

PHP Advanced Features: Best Practices in Object-Oriented Programming PHP Advanced Features: Best Practices in Object-Oriented Programming Jun 05, 2024 pm 09:39 PM

PHP Advanced Features: Best Practices in Object-Oriented Programming

Explore object-oriented programming in Go Explore object-oriented programming in Go Apr 04, 2024 am 10:39 AM

Explore object-oriented programming in Go

Analysis of object-oriented features of Go language Analysis of object-oriented features of Go language Apr 04, 2024 am 11:18 AM

Analysis of object-oriented features of Go language

C++ function inheritance explained: When should inheritance not be used? C++ function inheritance explained: When should inheritance not be used? May 04, 2024 pm 12:18 PM

C++ function inheritance explained: When should inheritance not be used?

Are there any class-like object-oriented features in Golang? Are there any class-like object-oriented features in Golang? Mar 19, 2024 pm 02:51 PM

Are there any class-like object-oriented features in Golang?

See all articles