This article describes the encapsulated inheritance polymorphism implemented by JavaScript using prototype prototype. Share it for your reference, as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/"> <html xmlns="http:///1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title> jsBased on prototypeprototypeEncapsulation inheritance polymorphism</title> </head> <body> <script> function Person(name,age) { =name; =age; } =function() { return ; } =function(name) { =name; } =function() { return ; } =function(age) { =age; } //-------------------- function Student(name,age,c) { =name; =age; =c; } =new Person(,);//Focus=function() { return ; } =function(c) { =c; } var a=new Person("Little",19); (()); //----------------------------------------- var b=new Student("Big",15,1); (()); </script> </body> </html>
Running results:
Small big big
Interested friends can use itOnline HTML/CSS/JavaScript code running tool:http://tools./code/HtmlJsRunTest the above code.
For more information about JavaScript, you can also view the topic of this site: "JavaScript object-oriented tutorial》、《Summary of JavaScript Errors and Debugging Skills》、《Summary of JavaScript data structure and algorithm techniques》、《JavaScript traversal algorithm and skills summary"and"Summary of JavaScript mathematical operations usage》
I hope this article will be helpful to everyone's JavaScript programming.