•与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>

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-24
  • 2021-08-28
  • 2021-07-30
猜你喜欢
  • 2022-01-01
  • 2021-08-10
  • 2022-12-23
  • 2022-12-23
  • 2021-08-28
  • 2021-10-04
  • 2022-02-15
相关资源
相似解决方案