继承:父类有的,子类也有。父类改变,子类也跟着变。
属性继承: 
    矫正this (window对象,矫正成object对象)
    fn .call(this是谁,参数1,参数2...);
    fn .apply(this是谁,[参数1,参数2...]);
    父类.apply(this,arguments);
方法继承:
    a).Worker.prototype = Person.prototype;
        问题:会触发引用 ,当改变worker的时候会改变Person的值
    b).
        for(var name in Person.prototype){
            Worker.prototype[name] = Person.prototype[name];
        }
 
        瑕疵:w1 instanceof Person         false
 
    c).
        Worker.prototype = new Person();
        瑕疵:w1.constructor 不等于Worker
 
    d).
        Worker.prototype = new Person();(原型链上赋值new Person所有的方法)
        Worker.prototype.constructor = Worker;(把它的构造函数指向worker)

面向对象写选项卡

function Tab(id){
    this.oBox = document.getElementById(id);
    this.aBtn = this.oBox.getElementsByTagName('input');
    this.aDiv = this.oBox.getElementsByTagName('div');
    this.iNow = 0;
    this.init();
}
Tab.prototype.init=function(){
    var _this = this;
    for(var i=0;i<this.aBtn.length;i++){
        this.aBtn[i].index = i;
        this.aBtn[i].onclick=function(){
            _this.iNow = this.index;
            _this.hide();
            _this.show();
        };
    }
};
Tab.prototype.hide=function(){
    for(var i=0;i<this.aBtn.length;i++){
        this.aBtn[i].className='';
        this.aDiv[i].className='';
    }
};
Tab.prototype.show=function(){
    this.aBtn[this.iNow].className='on';
    this.aDiv[this.iNow].className='on';
};
window.onload=function(){
    new Tab('div1');
}; 

面向对象写拖拽

function Drag(id){
    this.oDiv = document.getElementById(id);
    this.disX = 0;
    this.disY = 0;
    this.init();
};
Drag.prototype.init=function(){
    var _this = this;
    this.oDiv.onmousedown=function(ev){
        var oEvent = ev||event;
        _this.fnDown(oEvent);
        return false;
    };
};
Drag.prototype.fnDown=function(ev){
    var _this = this;
    this.disX = ev.clientX-this.oDiv.offsetLeft;
    this.disY = ev.clientY-this.oDiv.offsetTop;
    document.onmousemove=function(ev){
        var oEvent = ev||event;
        _this.fnMove(oEvent);
    };
    document.onmouseup=function(){
        _this.fnUp();
    };
    this.oDiv.setCapture&&this.oDiv.setCapture();
};
Drag.prototype.fnMove=function(ev){
    this.oDiv.style.left = ev.clientX-this.disX+'px';
    this.oDiv.style.top = ev.clientY-this.disY+'px';
};
Drag.prototype.fnUp=function(){
    document.onmousemove=null;
    document.onmouseup=null;
    this.oDiv.releaseCapture&&this.oDiv.releaseCapture();
};
window.onload=function(){
    new Drag('div1');
}; 
 

javascript面向对象事件继承的更多相关文章

  1. JavaScript面向对象(三)——继承与闭包、JS实现继承的三种方式

      前  言 JRedu 在之前的两篇博客中,我们详细探讨了JavaScript OOP中的各种知识点(JS OOP基础与JS 中This指向详解 . 成员属性.静态属性.原型属性与JS原型链).今天 ...

  2. Javascript 面向对象编程—继承和封装

      前  言 Javascript是一种基于对象(object-based)的语言,你遇到的所有东西几乎都是对象.但是,它又不是一种真正的面向对象编程(OOP)语言,因为它的语法中没有class(类) ...

  3. javascript面向对象中继承实现?

    面向对象的基本特征有:封闭.继承.多态. 在javascript中实现继承的方法: 1.原型链(prototype chaining) 2.call()/apply() 3.混合方式(prototyp ...

  4. 【前端学习】javascript面向对象编程(继承和复用)

    前言       继承,代码复用的一种模式.和其它高级程序语言相比,javascript有点点不一样,它是一门纯面向对象的语言,在JS中,没有类的概念,但也可以通过原型(prototype)来模拟对象 ...

  5. javascript 面向对象的继承的实现

    JavaScript 中的面向对象的初步认识 上面这篇简单的记录了我对 JS面向对象实现的一点初步认识和了解,下面继续研究JS面向对象,实现继承和多态. 之前的学习我了解到了 :构造函数加属性,原型p ...

  6. javascript面向对象:继承、多态

    继承 js中同样可以实现类的继承这一面向对象特性,继承父类中的所有成员(变量和属性),同时可扩展自己的成员,下面介绍几种js中实现继承的方式: 1,对象模仿:通过动态的改变 this 指针的指向,实现 ...

  7. Javascript面向对象之继承

    与类的创建篇一样,这里先贴出最终代码,再做详细分析: // 创建一个父类 function SuperType(){ this.company = 'alibaba'; } function SubT ...

  8. Javascript 面向对象之继承

    本文参考书籍<<Javascript高级程序设计>> js继承方式:实现继承,主要依靠原型链实现. 原型链:基本思想:利用原型让一个引用类型继承另一个引用类型的属性和方法. 这 ...

  9. javascript 面向对象(实现继承的几种方式)

     1.原型链继承 核心: 将父类的实例作为子类的原型 缺点:  父类新增原型方法/原型属性,子类都能访问到,父类一变其它的都变了 function Person (name) { this.name ...

随机推荐

  1. MongoDB 学习笔记(四)C# 操作MongoDB

    C#驱动对mongodb的操作,目前驱动有两种:官方驱动和samus驱动,不过我个人还是喜欢后者, 因为提供了丰富的linq操作,相当方便. 官方驱动:https://github.com/mongo ...

  2. config windows virtual machine on mac

    1.download virtualbox  and related extension pack from http://www.oracle.com/technetwork/server-stor ...

  3. datagridview的某些属性以及增删改查

    private void button1_Click(object sender, EventArgs e) //查询 { dataGridView1.AutoGenerateColumns = fa ...

  4. Qt之设置QWidget背景色

    简述 QWidget是所有用户界面对象的基类,这意味着可以用同样的方法为其它子类控件改变背景颜色. Qt中窗口背景的设置,下面介绍三种方法. 使用QPalette 使用Style Sheet 绘图事件 ...

  5. CodeForces Round #250 Div2

    A. The Child and Homework 注意仔细读题,WA了好多次,=_= #include <cstdio> #include <cstring> #includ ...

  6. Intellij IDEA13 创建多模块Maven项目

    目标:构建一个类似于如下图所示的这种结构的Maven项目. 首先,需要选中“File”——>“New Project”如下图所示 选中“Maven”,设置项目名称与项目构建地址,点击“Next” ...

  7. codevs 1138 聪明的质监员

    二分+前缀和. #include<iostream> #include<cstdio> #include<cstring> #include<cmath> ...

  8. #1406 - Data too long for column (转)

    转自:(http://blog.sina.com.cn/s/blog_5115a74c01008e40.html) ERROR (): Data too long for column 解决方法 修改 ...

  9. xunsearch迅搜体验

    安装与启动 http://www.xunsearch.com/doc/php/guide/start.installation 编写配置文件 http://www.xunsearch.com/doc/ ...

  10. gridview自定义表头

    gridview为我们提供了丰富的接口,用于满足自定义需求. 通常asp:gridview会根据绑定的列Columns自动生成表头,展现在前台元素. 序号 类别 有时候需要复杂一些的表头. 序号 类别 ...