javascript--继承&多态
来源:互联网 发布:淘宝美女口水 编辑:程序博客网 时间:2024/06/05 14:51
<script type="text/javascript">/*之前说到 php 类和对象 js 的对象 php只需要类继承了 new个对象也是继承了js则是通过原型继承 */// 爸爸function gorila(){this.eat = function(){alert('amuamu');}}// 儿子function human(){}// 人的抽象函数就向猩猩对象学到了东西human.prototype = new gorila();var man = new human();man.eat();// man在自己的函数里没找到就到原型对象去找console.log(man);/*得到__proto__是个对象也就是new gorila指向其原型对象*/var gorila = new gorila();// 就是这个new gorila();console.log(gorila);
多态
<script type="text/javascript">function Dog(){this.bark = null;}function hashiqi(){this.bark = function(){alert('ashash');}}function samo(){this.bark = function(){alert('sssss');}}hashiqi.prototype = samo.prototype = new Dog();var h = new hashiqi();var s = new samo();function test(dog){dog.bark();} test(h);test(s);/*静态方法 不需要new对象来调用*/samo.jtff = function(){alert('heihei');}samo.jtff();/*jtff方法是属于函数本身的,和返回的对象没关系;而函数内的bark方法要new对象才能调用*//*jQuery 静态 先给script加上src$.sing = funcion(){alert()*/</script>
0 0
- javascript--继承&多态
- javascript继承
- javascript继承
- javascript 继承
- Javascript继承
- Javascript继承
- javascript继承
- Javascript继承
- javascript继承
- JavaScript 继承
- javascript 继承
- JavaScript 继承
- javascript 继承
- javascript 继承
- Javascript继承
- Javascript继承
- Javascript 继承
- JavaScript 继承
- 你也来学设计模式之策略模式
- 最详细的Log4j使用教程
- (1) 自定义分页<采用jsp和Java实现>
- 使用NSClassFromString加载类
- $.ajax获取返回值
- javascript--继承&多态
- 第一个博客
- Android小知识清单(二)
- html调试研究(二)-样式修改的一些规范
- VB中调用VC++开发的DLL
- Arduino: L293D for a DC motor
- 最新Eclipse SVN插件地址
- leetcode刷题系列C++-rotate image
- 原html标签分类