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

 

posted @ 2017-05-09 19:50  haveProgress  阅读(110)  评论(0编辑  收藏  举报