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>
运行代码
查看全文
相关阅读:
Python之os模块
Python之加密模块
Python之random模块
Python之操作MySQL数据库
Python之操作Excel
Jmeter之发送请求入参必须使用编码格式、Jmeter之发送Delete请求可能入参需要使用编码格式
PAT B1008 数组元素循环右移问题 (20 分)
PAT B1007 素数对猜想 (20 分)
PAT B1006 换个格式输出整数 (15 分)
PAT B1005 继续(3n+1)猜想 (25 分)
原文地址:https://www.cnblogs.com/jikey/p/1728014.html
最新文章
随机生成一个0到100的数,让用户猜,允许猜5次,每次猜大了或猜小了,都要给出提示,最后给出正确答案
求两圆相交面积
找最小的差和个数
哈希求众数
博弈
鞍点问题
浏览器内核
伪类
margin和padding设置百分比
absolute,fixed,relative,static,inherit
热门文章
正则表达式
4.10-4.13
JS面向对象的实现和原理
线程
流
MYSQL安装不上,startservice不响应
前端之HTML
Excel之批量改变特定字体颜色(转载)
jmeter之批量修改请求路径
Python之time模块
Copyright © 2011-2022 走看看