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>
运行代码
查看全文
相关阅读:
CentOS7.2上安装Python3.6
Ubuntu 18.04 安装配置 MySQL 5.7
CentOS 使用 sudo 遇到 command not found 问题解决
一个恼人的文件名问题
CentOS7 安装配置备忘录
Win7 + CentOS7 双系统
C++ 精英化趋势
CentOS7 安装配置 MySQL 5.7
pip "Cannot uninstall 'six'. It is a distutils installed project..." 解决方法
Linux 系统假死的解决方案
原文地址:https://www.cnblogs.com/jikey/p/1728014.html
最新文章
完美且精准的 IE10- 版本检测。
JS 实现可停顿的垂直滚动
数字自动增长
精彩 JavaScript 代码片段
CSS常用选择器名
通过原生JS实现为元素添加事件
原生JS查找元素
LR脚本录制方式说明
根据用户的积分、获取用户的等级,如果用户没有积分,则显示没有等级
Linux上通过MySQL命令访问MySQL数据库时常见问题汇总
热门文章
GoAccess自动分割Nginx日志
GoAccess安装和使用介绍
测试术语
水杯测试用例-转载自网上
测试基础知识(需求分析及用例设计)
Windows环境中,通过Charles工具,抓取安卓手机、苹果手机中APP应用的http、https请求包信息
MySQL基础环境_安装配置教程(Windows7 64或Centos7.2 64、MySQL5.7)
Windows基础环境_安装配置教程(Windows7 64、JDK1.8、Android SDK23.0、TortoiseSVN 1.9.5)
Linux基础环境_安装配置教程(CentOS7.2 64、JDK1.8、Tomcat8)
CentOS7.2上搭建httpbin环境
Copyright © 2011-2022 走看看