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>
  • 相关阅读:
    POJ3613 Cow Relays 经过n条边的最短路
    UML笔记(六)
    UML主要内容及参考资料
    UML笔记(五)
    UML笔记(一)
    UML笔记(三)
    UML笔记(四)
    软件工程——第十一章 软件项目管理
    软件工程——第十章 软件工程管理
    UML笔记(二)
  • 原文地址:https://www.cnblogs.com/timy/p/1181437.html
Copyright © 2011-2022 走看看