对象的创建、使用及向String对象添加方法(prototype的使用)
来源:互联网 发布:展会源码 编辑:程序博客网 时间:2024/06/05 02:02
prototype 属性使您有能力向对象添加属性和方法。
语法
object.prototype.name=value
<html><head><script language="javascript" type="text/javascript">//对象的定义,使用(名片示例)function Card(name, address, work, home){this.name = name;this.address = address;this.work = work;this.home = home;this.show = ShowCard;}function ShowCard(){l1 = "name:" + this.name + ".<br/>";l2 = "address" + this.address + ".<br/>";l3 = "work" + this.work + ".<br/>";l4 = "home" + this.home + ".<br/>";document.write(l1,l2,l3,l4);}var tom = new Card("tom","河口","程序员","北京");tom.show();//向String对象添加一个heading方法。将字符串显示为标题,然后用这个方法显示3个标题function addhead(level){html = "H" + level;text = this.toString();a = "<" + html + ">";b = "<" + html + "/>";return a + text + b;}String.prototype.heading = addhead;document.write("this is h1".heading(1)+"</br>");document.write("this is a h3".heading(3)+"</br>");document.write("this is a h5".heading(5)+"</br>")</script></head></html>
0 0
- 对象的创建、使用及向String对象添加方法(prototype的使用)
- 通过 prototype 为 JavaScript 的 String 对象添加方法(函数)
- 创建Graphics对象的方法及使用
- javascript使用原型(prototype)方法创建对象
- 使用prototype扩展JS内部对象String的功能
- 从对象创建 到构造函数以及原型对象(prototype的使用,属性的共享)
- Javascript prototype属性使用(给内置对象添加新的方法,方便调用)
- String类对象的创建使用,雇员对象的操作
- Javascript中使用String对象的方法
- String字符串对象方法的使用
- Jquery中使用$append出现添加两次及Jquery对象多次使用的方法
- String字符串对象的创建及管理
- 关于JavaScript的String及Math对象的方法的使用
- 000053:创建String对象,使用lastIndexOf()方法查看字符串str中空字符串的位置
- JavaScript(js)对象的创建方法与使用
- 课时37|String 对象的创建和使用
- C#高级——创建Person类,分别使用面向过程的方法和面向对象的方法
- String对象的创建
- 数据库之数据的插入与显示之二
- 流程控制(学习C语言的转折点)
- 数据库
- 系统实现邮件、拨号、SMS、浏览器的调用
- OpenCV 开发环境环境搭建(win10+vs2015+opencv 3.0)
- 对象的创建、使用及向String对象添加方法(prototype的使用)
- 如何防止文件备份到iCloud和iTunes
- IE 兼容与CSS选择器
- 黑马程序员————Android中LayoutInflater布局解析的使用
- Ubuntu忘记密码解决办法
- iOS 微信支付接入最新的完整流程
- uva 1349 - Optimal Bus Route Design(完美匹配)
- 关于mysql添加用户和删除用户遇到的一些问题
- struts2 获得request session application的四种方式