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>
运行代码
查看全文
相关阅读:
WCF webHttpBinding协议上传接收文件
mysql 用存储过程和函数分别模拟序列
angular 下载文件
Firebird 备份与恢复
sql 等额本息
Firebird 手动安装 Legacy_Auth 登陆认证
Firebird 获取用户表及字段
Firebird shadow
Linux的安装(虚拟机环境)与基础配置
第 3 章 数据库系统 3.5备份与恢复
原文地址:https://www.cnblogs.com/jikey/p/1728014.html
最新文章
一文搞定 Git 相关概念和常用指令
Python 转义字符中没有这个 「e」 !
我的常规爬虫流程分享
Python | 一行命令生成动态二维码
技术学得好,老婆加班少!
如何优雅地使用 rm 防止误删除?
使用 py2exe 打包 Python 程序
交互式 shell 玩转 Python
1 行代码,实现微信消息发送
使用 Python 发送短信?
热门文章
理解正常代理与反向代理的区别(转)
JS Date函数在safari中的问题
PHP调用百度api生成短网址&根据短网址恢复长网址
TP2.1 加载扩展配置文件参数
ThinkPHP出现项目目录不可写,目录无法自动生成
Yii2:记一次尴尬的bug
转:详解PV、UV、VV、IP及其关系与计算
分析apache日志,统计访问量
YII2使用gii
YII2应用结构
Copyright © 2011-2022 走看看