zoukankan      html  css  js  c++  java
  • Function原生类型

    •与Array,String等类型处于同等地位
    •每个方法均为Function类型的实例
    –typeof(Array) == typeof(Function) == “function”
    •方法调用时根据发起的对象来确定this上下文引用
    •Function.prototype.apply(instance, args)
    •Function.prototype.call(instance, [ arg1 [ , arg2 [ , … ] ] ])


    html
        <div id="info"></div>
        
    <script language="javascript" type="text/javascript">
            function display(text)
            {
                document.getElementById(
    "info").innerHTML += (text + "<br />");
            }
            
            function aMethod()
            {
                var result 
    = this.toString();
                
    for (var i = 0; i < arguments.length; i++)
                {
                    result 
    += ("" + arguments[i]);
                }
                
                
    return result;
            }
            
            var a 
    = new String("I am string A");
            var b 
    = new String("I am string B");
            a.aMethod 
    = b.aMethod = aMethod;
            
            display(
    "aMethod(): " + aMethod());
            display(
    "a.aMethod(): " + a.aMethod());
            display(
    "b.aMethod(): " + b.aMethod());
            
            display(
    "a.aMethod.call(b, 1, 2, 3): " + a.aMethod.call(b, 123));
            display(
    "b.aMethod.apply(a, [1, 2, 3]): " + b.aMethod.apply(a, [123]));
        
    </script>
  • 相关阅读:
    PTA——List Leaves
    pta——电话聊天狂人(c二叉树实现)
    Anti-SG游戏 与 SJ定理笔记(反Nim博弈)
    Unicode代码点与代码单元
    奇偶校验位
    IPv6与IPv4的位数
    0- win10配置java环境变量问题
    小计划
    路径问题
    getResource(path)的注意事项
  • 原文地址:https://www.cnblogs.com/timy/p/1181437.html
Copyright © 2011-2022 走看看