js 原型prototype

function MyObject(name, size)
{
  this.name = name;
  this.size = size;
}

MyObject.prototype.height = "2.26 meters";
MyObject.prototype.tellHeight = function()
{
  return "height of "+this.name+" is "+this.height;
}

///////使用
var myobj1 = new MyObject("haha", 3);
if (myobj1.tellHeight)
{
  domDiv.innerHTML += myobj1.tellHeight()+";
}

http://www.cnblogs.com/lidabo/archive/2012/01/05/2313481.html

原文地址:https://www.cnblogs.com/geekjsp/p/6832341.html