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>
运行代码
查看全文
相关阅读:
报表中的图形是怎么做出来的?如何在其中实现地图?
多维分析的本质计算是什么?能做什么又不能做什么?
报表工具对比选型系列用例——多源分片报表
报表工具怎样适应移动端?
报表工具怎样适应移动端?
互联网技术部门该如何管理
更好用 更简单的Java缓存框架 jscache
古人是怎么排行
Spark ML 机器学习之Word2Vec
Spark ML之高级数据源
原文地址:https://www.cnblogs.com/jikey/p/1728014.html
最新文章
goto语句
continue语句
break语句
嵌套循环
for循环语句
do...while循环语句
while循环语句
switch语句
三目运算符
关于程序流程控制
热门文章
什么是可测试性需求(DFT)?
《技术规划和路标开发实践》北京公开课通知!(2020-11-6~7 北京)
浅谈测试原始需求的提取(经典好文)
基于功能树分析(FTA)功能级FIT硬件测试方法
华为UI测试-PC解决方案
吐槽下若依(RuoYi)系统的权限系统(shiro和spring-security)
报表工具对比选型系列
报表工具对比选型系列用例——过程计算
报表工具对比选型系列
报表工具对比选型系列用例——排名及跨行组统计
Copyright © 2011-2022 走看看