zoukankan
html css js c++ java
Js对象继承
1.对象冒充
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Document</title> </head> <body> <script type="text/javascript"> function Person(personName){ this.name = personName; this.sayName = function(){ alert('my name is ' + this.name); } } function Man(name, age){ //Person.call(this, name); Person.apply(this,new Array(name)); this.age = age; this.sayAge = function(){ alert('my age is ' + this.age); } } var m = new Man('jikey', 'tom', 29); m.sayName(); m.sayAge(); </script> </body> </html>
运行代码
2.混合方式
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Document</title> <style> </style> <script> function Person(name){ this.name = name; } Person.prototype.sayName = function(){ alert('My name is ' + this.name);} function Man(name, age){ Person.call(this, name); this.age = age; } Man.prototype = new Person(); Man.prototype.sayAge = function(){ alert('My age is ' + this.age);} var tom = new Man('tom', 29); var jikey = new Man('jikey', 29); tom.sayAge(); tom.sayName(); jikey.sayName(); </script></head> <body> </body> </html>
运行代码
查看全文
相关阅读:
开源情报 Advise
介绍几本搜索引擎的基础书
Internet上的图像检索技术
交易系统 转 武胜
MySql数据库导出csv 武胜
C# Process.Start()方法详解 武胜
转 嵌入处部程序 武胜
网际风通视接口 武胜
C# Process运行cmd命令的异步回显 武胜
RBreaker 武胜
原文地址:https://www.cnblogs.com/jikey/p/1728014.html
最新文章
LINQ 之Union All/Union/Intersect操作
C# 写入XML方法
WCF服务的执行边界
[转]固定WinForm窗体样式,不因系统设定而变化
SQL Hint
SQL通配符
zz数据库查询XML结构,FOR XML PATH 语句的应用
zz美国最新最时尚的英语词汇so hot!
zz用电脑说爱你!看看程序员如何告白
经典数据库问题
热门文章
聚集索引与非聚集索引
使用EventViewer记录VSTO addin启动错误
SQL性能优化总结
开源情报 的 重要连接 hyperlink
BladeCenter JS 21 相关配置参数
被 EI 收录 的文章
乙肝康复的标准
Intelligent Information Integration for the Semantic Web 语义网的智能信息整合
多媒体信息检索技术简介 (基于内容的视频检索)
教育体制改革为什么只革教师的命不革校长的命
Copyright © 2011-2022 走看看