Jquery Call ,apply,callee

     //call

        function A() {

            name = "abc";

            this.ShowName = function (val) {

                alert(name + "," + val);

            }

        }



        function B() {

            name = "def";

        }

        var a = new A();

        var b = new B();

        a.ShowName.call(b, "123");



        //返回的是 def, 123



        //apply

        function A1(arr) {

            this.value = 105;

            if (arguments[1]) {

                if (arguments[1] < 100)

                    this.value = 88;

                else

                    this.value = arguments[0]

            }

        };

        function B1(arrt) {

            A1.apply(this, arguments);

            console.log("B1返回结果:"+this.value);

        }

        B1(66, 105);

        //返回 66;



        //callee

        function A2(x)

        {

            if (x > 5)

            {

                console.log(x);

                arguments.callee(x - 1);

            }

        }

        A2(10);

       //返回:10,9,8,7,6

 

你可能感兴趣的:(jquery)