JS中arguments.calleeの使い方と属性

3283 ワード

//———————arguments基本使用——————//
-- -- -- -- --
``
function argTest(a, b, c, d) {
ここにはチップ`var numargs=argumentsと書く.length;//実数数var expargs=argTest.length;//パラメータの数.alert(「実パラメータ数:」+numargs);alert(「形数:」+expargs);alert(“arguments[0]=” + arguments[0]);//これはIEと火狐の下でalert(「argTest[0]=」+argTest[0]);//IE8.0-undefined、Mozilla/5.0サポート.alert(typeof(arguments));//Argumentsはオブジェクト}argTest(1,2)
//   ,arguments.length      ,   .length      //
//----------------caller    ------------------------//  
function callerDemo() {
    if(callerDemo.caller) {
        alert(typeof(callerDemo.caller)); //       (function)
        alert(callerDemo.caller); //         
        var a = callerDemo.caller.arguments[0];
        alert(a);
    } else {
        alert("this is a top function");
        alert(callerDemo.caller);
        alert(typeof(callerDemo.caller)); //typeof(null)  object
    }
}

function handleCaller() {
    callerDemo();
}
callerDemo();
handleCaller("  1", "  2");

function calleeDemo() {
    alert(arguments.callee); //      function     
}
//----------------      ???-----------------------//
function Sing() {
    with(arguments.callee)
    alert(arguments.callee);
    alert(author + ":" + poem);
};
Sing.author = "  ";
Sing.poem = "     ,     。     ,     ";
Sing();
Sing.author = "  ";
Sing.poem = "     ,     。     ,     ";
Sing();
//          ,       ?
//    :alert(arguments.callee)       (arguments.callee)   alert    ,       author poem  。
//----------------      arguments.callee-----------------------//
//----------------caller          ------------------------//
//       ;
(function(arg0, arg1) {
    alert(arguments.callee);
    alert("     :" + arguments.callee.length); //               ?     。
})();

function anonymousFnCall() {
    alert("Hello world");
    this.a = "     ";
    //       
    this.show = function(arg0, arg1) {
        alert(this.a);
        alert("     :" + arguments.callee.length)
    };
    this.sayHello = function() {
        return function() { alert("hello"); };
    };
}
var ano = new anonymousFnCall();
ano.show('1'); //    arguments.callee.length      ,  arguments.callee       .length
ano.sayHello()(); //           ();
//   ,   .callee          ,arguments.callee           //
//-----------------apply call---------------------//
function ObjectA() {
    this.getMsg = function(msg) { alert(msg) }
}

function ObjectB() {
    //ObjectA.call(this);
    ObjectA.apply(this, arguments);
    getMsg('Object  ');
}
ObjectB('  0');
//-----------------apply call    ---------------------//
function act() {
    for(var i = 0; i < arguments.length; i++) {
        document.write(this.t[i] + ": " + arguments[i] + "
"); } } function actby() { this.t = [" 1 :", " 2 :"]; } //call(obj,arg1,arg2...); act.call(new actby(), " 1 call", " 2 call"); //apply(obj,[arg1,arg2...]); act.apply(new actby(), [" 1 apply", " 2 apply"]); //--apply call --//