继承:父类有的,子类也有。父类改变,子类也跟着变。
属性继承: 
    矫正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. php实现新闻页面

    首页 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8& ...

  2. Codeforces Round #362 (Div. 2) A.B.C

    A. Pineapple Incident time limit per test 1 second memory limit per test 256 megabytes input standar ...

  3. 一、导入、导出远程Oracle数据库

    一.导入.导出远程Oracle数据库  其语法实示例如下:    imp/exp [username[/password[@service]]]   其中service是服务实例名,关于如何创建服务实 ...

  4. android 事件处理机制之requestDisallowInterceptTouchEvent

    当手指触摸到屏幕时,系统就会调用相应View的onTouchEvent,并传入一系列的action.当有多个层级的View时,在父层级允许的情 况下,这个action会一直向下传递直到遇到最深层的Vi ...

  5. 配置spring上下文

    <context-param> <param-name>contextConfigLocation</param-name> <param-value> ...

  6. hdu1054(二分图匹配)

    题意很简单,在一颗树上找最小点覆盖. 将树染成黑白两色,构成一张二分图,然后最大匹配==最小点覆盖即可,所以一次匈牙利就可以求出来了 hdu1054 #include <iostream> ...

  7. C# 类的访问修改符

    C#共有五种修饰符:public.private.protected.internal.protected internal. ◆public:公有,对所有类可见,不受任何限制 ◆protected: ...

  8. How to: Modify a Project System So That Projects Load in Multiple Versions of Visual Studio

    http://msdn.microsoft.com/en-us/library/hh266706(v=VS.110).aspx

  9. Perfect smooth scrolling in UITableViews

    https://medium.com/ios-os-x-development/perfect-smooth-scrolling-in-uitableviews-fd609d5275a5 Diffic ...

  10. DOM对象常用对象的方法和属性

      HTML文档中的常用节点类型: 接口 nodeType 备注 Element 1 元素节点 Text 3 文本节点 Document 9 Document Comment 8 注释文本 Docum ...