A test of javascript's inheritance
来源:互联网 发布:网络公关营销公司 编辑:程序博客网 时间:2024/04/29 14:14
This is a simple test of javascript's inheritance,you also can change the "apply" method to "call". the result is same.
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
- <html>
- <head>
- <title>Javascript Class extend test</title>
- <meta name="Generator" content="EditPlus">
- <meta name="Author" content="^_^-Stefli,^_^-Beluga">
- <meta name="Keywords" content="">
- <meta name="Description" content="">
- </head>
- <body>
- <script>
- function BaseClass() {
- this.field = "field";
- this.getMethod = function() {
- return "getMethod";
- }
- this.getOverrideMethod = function() {
- return "getOverrideMethod";
- }
- }
- function SubClass() {
- BaseClass.call(this);
- this.f = "f";
- this.getM = function() {
- return "getM";
- }
- }
- function SubSubClass() {
- SubClass.call(this);
- this.subf = "subf";
- this.getSubM = function() {
- return "getSubM";
- }
- this.getOverrideMethod = function() {
- return "override getOverrideMethod";
- }
- }
- System = {}
- System.out = {}
- System.out.println = function() {
- if(arguments.length == 1) {
- document.write(arguments[0] + "<br />/n");
- } else {
- document.write("<br />/n");
- }
- }
- var subClass = new SubSubClass();
- System.out.println("1. field = /"" + subClass.field + "/"/tmethod = /"" + subClass.getMethod() + "/"");
- System.out.println("2. f = /"" + subClass.f + "/"/tm = /"" + subClass.getM() + "/"");
- System.out.println("3. subf = /"" + subClass.subf + "/"/tsubm = /"" + subClass.getSubM() + "/"");
- System.out.println("4. override the method = /"" + subClass.getOverrideMethod() + " of BaseClass/"");
- </script>
- </body>
- </html>
here is the result:
===================================================
1. field = "field" method = "getMethod"
2. f = "f" m = "getM"
3. subf = "subf" subm = "getSubM"
4. override the method = "override getOverrideMethod of BaseClass"
===================================================
- A test of javascript's inheritance
- It's a test
- It's a test
- it's a test
- 理解John Resig's 'Simple JavaScript Inheritance'代码
- Inheritance: 'A' is an inaccessible base of 'B'
- It's just a test!
- it's a test page
- MySQL test: it’s because of RQG that we now have a really solid MySQL Server
- Object-orientation and inheritance in JavaScript: a comprehensive explanation
- Wait A Moment, JavaScript Does Support Multiple Inheritance!
- Summary of Inheritance
- how to test a file 's existence
- Classical Inheritance in JavaScript
- Classical Inheritance in JavaScript
- JavaScript inheritance by example
- Inheritance in JavaScript 继承
- Classical Inheritance in JavaScript
- Firefox - 更新 - 3.0.3
- 百万电脑被病毒秘密控制 院士专家共商出路
- 一些常用的正则表达式
- 转并学习: 将rar文件转换为zip格式
- 一些不错的java题
- A test of javascript's inheritance
- 花枝招展
- 【求助】2008年9月30号 深圳到杭州火车票:1张
- 一个北大毕业生对在校生和已毕业的朋友说的话
- 关于RedHat Linux 9.0下Kylix 3会出现的四个问题的完满解决办法
- Direct3D中的Pick技术
- Java语言的细节
- 嵌入式文件系统的构建
- ASP.NET程序中常用代码汇总(一)