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>
运行代码
查看全文
相关阅读:
【模板】字符串匹配的三种做法(Hash、KMP、STL)
《为了你我愿意热爱整个世界》书评
将.bat文件设置成windows服务(解决odi代理开机自动启动的问题)
Oracle学习笔记 -- 内存结构
Oracle学习笔记 -- 前言
在实验静态块等时遇到到关于main函数的问题
关于main方法调用main方法的问题
关于静态块、静态属性、构造块、构造方法的执行顺序
left join on and与left join on where的区别(转载)
Oracle中的正则表达式(REPLACE 和REGEXP_REPLACE)---转载自http://database.51cto.com/art/201009/228270.htm
原文地址:https://www.cnblogs.com/jikey/p/1728014.html
最新文章
【NOIp2002】矩形覆盖
NewBlog
卡常小tips
NOIP前做题日记
雅礼中学七天乐(游记
关于 PushinL
博主退役公告
zkw线段树模板练习。
割点和桥
【模板】二分图匹配
热门文章
QBXT金秋测试题解qwq
状压DP·笔记
数据结构笔记。
Luogu3387 缩点
关于 legend_noa
CSP花钱买教训记
NOIp2018游记
洛谷10月月赛II题解
【NOIp2004提高组】食虫算 题解
求最小环 —— 并查集 与 Floyd
Copyright © 2011-2022 走看看