mercredi 28 juin 2017

javascript about AOP

review my code make it print expected result thax


    var Obj = (function () {
            var b = 'b',
                    _f = function () {
                        // print arguments
                        Array.prototype.push.call(arguments,b);
                        console.log(arguments,b);
                    }

            return {
                f:_f
            };
        })();


        //rewrite Obj.f
        Obj.f = function () {
            // add parameters dynamically
            Array.prototype.push.call(arguments,333);

            // it dose not work
            Obj.f.apply(Obj.f,arguments);
        }


        //when I rewrite Obj.f how to make it print result below

        // expected result print 111 333 'b'
        Obj.f(111);
        // expected result print 666 333 'b'
        Obj.f(666);
        // expected result print 444 333 'b'
        Obj.f(444);

Aucun commentaire:

Enregistrer un commentaire