zoukankan      html  css  js  c++  java
  • js 一些常用东西

    javascript中apply()和call()方法的区别:

    function.call(this, arg1,arg2,arg3) == function.apply(this, arguments)==this.foo(arg1, arg2, arg3)

    call, apply都属于Function.prototype的一个方法,它是JavaScript引擎内在实现的,因为属于Function.prototype,所以每个Function对象实例,也就是每个方法都有call, apply属性.既然作为方法的属性,那它们的使用就当然是针对方法的了.这两个方法是容易混淆的,因为它们的作用一样,只是使用方式不同.

    参考:

    http://msdn.microsoft.com/en-us/library/ie/4zc42wh1(v=vs.94).aspx

    http://msdn.microsoft.com/en-us/library/ie/h2ak8h2y(v=vs.94).aspx

    http://www.cnblogs.com/fighting_cp/archive/2010/09/20/1831844.html

    寄生组合继承(Parasitic Combination Inheritance):

    function SuperType(name){
        this.name = name;
        this.colors = ["red", "blue", "green"];
    };
    
    SuperType.prototype.sayName = function(){
        alert(this.name);
    };
    
    function SubType(name, age){
        SuperType.call(this, name);
        this.age = age;
    }
    
    SubType.prototype = new SuperType();
    SubType.prototype.constructor = SubType;
    SubType.prototype.classname = "SubType";
    
    
    SubTYpe.prototype.sayAge = function(){
        alert(this.age);
    };
  • 相关阅读:
    kubenetes-学习
    k8s-字段
    Spring Boot集成mongodb
    synchronized关键字
    Scala手记
    Python数据结构&封装解构
    Scala基础之集合
    Scala基础之集合常用方法
    Scala(2.12)之collection基本操作
    Scala基础之集合(数组)
  • 原文地址:https://www.cnblogs.com/amosleaf/p/3042655.html
Copyright © 2011-2022 走看看