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>
运行代码
查看全文
相关阅读:
ModbusRTU模式和结束符(转)
modbus字符串的结束符介绍
IAR平台移植TI OSAL到STC8A8K64S4A12单片机中
实时系统概念
单片机的存储区范例
如何实现返回上一个页面,就像点击浏览器的返回按钮一般
spring项目中的定时任务实现和问题解决
context-param与init-param的区别与作用
Chapter 1 First Sight——16
一个好用简单的布局空间EasyUI
原文地址:https://www.cnblogs.com/jikey/p/1728014.html
最新文章
mysql varchar
php 今天 昨天 明天 时间戳
mysql 判空
对编程语言的数据类型的理解
smarty模版出现错误提示出现了不期望的字符
php 301
Linux硬盘分区和格式化
MySQL中多表删除方法(转载)
本地plsqldev.exe连接远端oracle数据库
Windows上RocketDock使用
热门文章
提高xshell使用效率
列出当前目录所有包含指定字符串的文件
windows可以登录qq,但无法打开浏览器页面
win10无法使用内置管理员账户打开
windows任务栏消失
主流单片机指令周期介绍
STM32的指令周期
stm32 HardFault_Handler调试及问题查找方法——飞思卡尔
stm32 HardFault_Handler调试及问题查找方法
pid 及参数调试方法
Copyright © 2011-2022 走看看