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>
  • 相关阅读:
    Sumdiv POJ
    Tallest Cow POJ
    P2280 [HNOI2003]激光炸弹(二维前缀和)
    Strange Towers of Hanoi POJ
    Manjaro (KDE)安装踩坑记录
    Petya and Array CodeForces
    CodeForces
    Philosopher’s Walk(递归)
    2018 icpc 青岛网络赛 J.Press the Button
    POJ 1003: Hangover
  • 原文地址:https://www.cnblogs.com/timy/p/1181437.html
Copyright © 2011-2022 走看看