首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

javascript prototype(原形)

2012-11-22 
javascript prototype(原型)如果有什么不对的地方请指出原型分为两种,一种是js 里的原型,还有就是原型框架

javascript prototype(原型)
如果有什么不对的地方请指出
原型分为两种,一种是js 里的原型,还有就是原型框架。这里讲的是js里的原型。

//演示prototype原型的用法,其实它等价于java中的类变量或者是静态变量//在原型里仅定义一些方法(方法一般是不会变的),常量等function Circle(x, y, z){    this.x = x;    this.y = y;    this.z = z;}new Circle(0, 0, 0);Circle.prototype.pi = 3.14159;function Circle_circumference(){    return 2 *    this.pi *    this.r;}Circle.prototype.circumference = Circle_circumference;Circle.prototype.area = function(){    return this.pi *    this.r *    this.r;}var c = new Circle(0.0, 0.0, 1.0);var a = c.area();var p = c.circumference();//ttt 演示用prototype给系统内置的String添加函数String.prototype.endsWith = function(c) {     return (c == this.charAt(this.length-1)) } var message = "hello world"; message.endsWith('h')  // Returns false message.endsWith('d')  // Returns true

热点排行
Bad Request.