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>
原文地址:https://www.cnblogs.com/timy/p/1181437.html