JS面向对象课件.pptVIP

  • 61
  • 0
  • 约1.19万字
  • 约 34页
  • 2017-05-12 发布于山西
  • 举报
JS面向对象课件

* 使用for .. in..可解决父类与子类代码一致的问题,但每次继承都需要编写for ..in语句。 示例中通过为Object对象定义一extend方法来简化JavaScript中继承操作,Object是JavaScript中的类 类的继承 Object.extend = function(destination, source){ for(prop in source){ destination[prop] = source[prop]; } return destination; } //使用TestB的extend方法继承Test function TestB(){} Object.extend(TestB.prototype, Test); Object.extend(TestB.prototype, { fa:function(){ alert(‘testb.fa’);}//重载Test的fa方法 } * 使用Object.extend方法也可以扩展javascript基本类型的功能,示例为String添加escape方法,将当前字符串转换成url编码 类的继承 Object.extend(String.prototype, { escape:function(){ return escape(th

文档评论(0)

1亿VIP精品文档

相关文档