Getting invalid formal parameters

This is a SO call

I would like to know how someone will get invalid formal parameters in a function without an object argumentsin order to simulate without knowing the format of the destination to destruct the parameter. This is not an ECMAScript question and applies only to JavaScript.

Your mySolutioncannot access argumentsor test. You are provided with an array argscontaining parameter names. You must return an object that has a property for each parameter, which is the parameter that was passed to the function. In short, results[prop]should === test[prop]. Your decision should not rely on bugs or security holes, as they may be missing in the future. The solution to this problem, which I mean, does not depend on any errors.

(function () {
    function mySolution ({
        var,
        this,
        function,
        if,
        return,
        true
    }) {
        // prohbit reference to arguments and the test object
        var test = arguments = null,

        args = ['var', 'this', 'function', 'if', 'return', 'true'],
        results = {};

        // put your solution here

        return results;
    };
    var test = {
        "var"     : {},
        "this"    : {},
        "function": {},
        "if"      : {},
        "return"  : {},
        "true"    : {}
    },
    results = mySolution(test),
    pass = true;

    for (var prop in test)
        if (test.hasOwnProperty(prop))
            if (results[prop] !== test[prop])
                pass = false;

    alert(pass ? "PASS" : "FAIL")
}());

Here is one of two possible solutions that I would make:

(function () {
    function mySolution ({
        var,
        this,
        function,
        if,
        return,
        true
    }) {
        // prohbit reference to arguments and the test object
        var test = arguments = null,

        args = ['var', 'this', 'function', 'if', 'return', 'true'],
        results = {};

        var i = args.length;
        while (i--) {
            results[args[i]] = eval("function::" + args[i]);
            // function::[args[i]] won't work unless you eval() it
        }

        return results;
    };
    var test = {
        "var"     : {},
        "this"    : {},
        "function": {},
        "if"      : {},
        "return"  : {},
        "true"    : {}
    },
    results = mySolution(test),
    pass = true;

    for (var prop in test)
        if (test.hasOwnProperty(prop))
            if (results[prop] !== test[prop])
                pass = false;

    alert(pass ? "PASS" : "FAIL")
}());

The solution works using the default namespace function::in combination with the realm eval().

For example: foo.function::barand foo.function::['bar']is one and the same foo.bar.

+5
8

100


(function () {
    function mySolution ({
        var,
        this,
        function,
        if,
        return,
        true
    }) {
        // prohbit reference to arguments and the test object
        var test = arguments = null,

        args = ['var', 'this', 'function', 'if', 'return', 'true'],
        results = {};

        // put your solution here
        var getEscUnicode = function(str) {
            var ret = "";
            for(var j = 0; j < str.length; j++) {
                var temp = parseInt(str.charCodeAt(j)).toString(16).toUpperCase();
                for(var i=0; i < 5 - temp.length; i++) {
                    temp = "0" + temp;
                }
                ret = ret + "\\u" + temp;
            }
            return ret;

        }
        for(var i = 0; i < args.length; i++) {
            results[args[i]] = eval(getEscUnicode(args[i]));
        }
        return results;
    };
    var test = {
        "var"     : {},
        "this"    : {},
        "function": {},
        "if"      : {},
        "return"  : {},
        "true"    : {}
    },
    results = mySolution(test),
    pass = true;

    for (var prop in test)
        if (test.hasOwnProperty(prop))
                if (results[prop] !== test[prop])
                        pass = false;

    alert(pass ? "PASS" : "FAIL")
}());

+4

PASS FireFox 3.0.13! "", :

<html>
<head>
<title></title>
<script>
(function () {
    function mySolution ({
        var,
        this,
        function,
        if,
        return,
        true
    }) {
        // prohbit reference to arguments and the test object
        var test = arguments = null,

        args = ['var', 'this', 'function', 'if', 'return', 'true'],
        results = {};

        // put your solution here
        Object.prototype._hasOwnProperty = Object.prototype.hasOwnProperty;
        Object.prototype.hasOwnProperty =
function(prop) {
 results[prop] = this[prop];
 return this._hasOwnProperty(prop);
}

        return results;
    };
    var test = {
        "var"     : {},
        "this"    : {},
        "function": {},
        "if"      : {},
        "return"  : {},
        "true"    : {}
    },
    results = mySolution(test),
    pass = true;

    for (var prop in test)
        if (test.hasOwnProperty(prop))
                if (results[prop] !== test[prop])
                        pass = false;

    alert(pass ? "PASS" : "FAIL")
}());

</script>
</head>
<body>
<!-- Put the body of your page below this line -->

<!-- Put the body of your page above this line -->
</body>
</html>

? , , , . =

+2

? : eval.

0

, , - callee.caller FF eval, .

, , eval "" , function({...}){}, .

, , , .

arguments , , <fn>.arguments , arguments ; null , arguments.

( test), , , .

(function () {
  function mySolution () {
    var test = arguments = null;
    return eval('test', (function(){ return arguments.callee.caller; })());
  };
  var test = {
    "var"   : {},
    "this"  : {},
    "function": {},
    "if"    : {},
    "return"  : {},
    "true"  : {}
  },
  results = mySolution(test),
  pass = true;

  for (var prop in test)
    if (test.hasOwnProperty(prop))
        if (results[prop] !== test[prop])
            pass = false;

  alert(pass ? "PASS" : "FAIL");
})();
0

! . ( , kangax). PASS FF 3.0.13:

<html>
<head>
<title></title>
<script>
(function () {
    function mySolution ({
        var,
        this,
        function,
        if,
        return,
        true
    }) {
        // prohbit reference to arguments and the test object
        var test = arguments = null,

        args = ['var', 'this', 'function', 'if', 'return', 'true'],
        results = {};

        // put your solution here
        var o = eval('arguments', mySolution)[0];
        for(var prop in o) {
         results[prop] = o[prop];
        }

        return results;
    };
    var test = {
        "var"     : {},
        "this"    : {},
        "function": {},
        "if"      : {},
        "return"  : {},
        "true"    : {}
    },
    results = mySolution(test),
    pass = true;

    for (var prop in test)
        if (test.hasOwnProperty(prop))
                if (results[prop] !== test[prop])
                        pass = false;

    alert(pass ? "PASS" : "FAIL")
}());

</script>
</head>
<body>
<!-- Put the body of your page below this line -->

<!-- Put the body of your page above this line -->
</body>
</html>
0

№3; , PASS FF 3.0.13

<html>
<head>
<title></title>
<script>
(function () {
    function mySolution ({
        var,
        this,
        function,
        if,
        return,
        true
    }) {
        // prohbit reference to arguments and the test object
        var test = arguments = null,

        args = ['var', 'this', 'function', 'if', 'return', 'true'],
        results = {};

        // put your solution here
        var o = mySolution[0];
        for (var prop in o) {
           results[prop] = o[prop];
        }

        return results;
    };
    var test = {
        "var"     : {},
        "this"    : {},
        "function": {},
        "if"      : {},
        "return"  : {},
        "true"    : {}
    },
    results = mySolution(test),
    pass = true;

    for (var prop in test)
        if (test.hasOwnProperty(prop))
                if (results[prop] !== test[prop])
                        pass = false;

    alert(pass ? "PASS" : "FAIL")
}());

</script>
</head>
<body>
<!-- Put the body of your page below this line -->

<!-- Put the body of your page above this line -->
</body>
</html>
0

I tried many ways. The view surrendered. But if you cannot break the system, change the system. My decision:


(function () {
    function mySolution ({
        var,
        this,
        function,
        if,
        return,
        true
    }) {
        // prohbit reference to arguments and the test object
        var test = arguments = null,

        args = ['var', 'this', 'function', 'if', 'return', 'true'],
        results = {};

        // put your solution here
/********** MY SOLUTION STARTS ******************/
        return null;
    }
    function mySolution ({
        var,
        this,
        function,
        if,
        return,
        true
    }) {
        // new function does not prohbit reference to arguments and the test object
        //var test = arguments = null,

        args = ['var', 'this', 'function', 'if', 'return', 'true'],
        results = {};
        for(var i =0; i < args.length; i++) {
            results[args[i]] = arguments[0][args[i]];
        }
/********** MY SOLUTION ENDS ******************/
        return results;
    };
    var test = {
        "var"     : {},
        "this"    : {},
        "function": {},
        "if"      : {},
        "return"  : {},
        "true"    : {}
    },
    results = mySolution(test),
    pass = true;

    for (var prop in test)
        if (test.hasOwnProperty(prop))
                if (results[prop] !== test[prop])
                        pass = false;

    alert(pass ? "PASS" : "FAIL")
}());
0
source
(function () {
    function mySolution ({ var, this, function, if, return, true }) {
    // prohbit reference to arguments and the test object
    var test = arguments = null, args = ['var', 'this', 'function', 'if', 'return','true'], results = {};
    //LAME...
    };
    mySolution=function(a){var results=a;
    //LAME...
    return results;
};
var test = {
      "var" : {},
      "this" : {},
      "function": {},
      "if" : {},
      "return" : {},
      "true" : {} }, results = mySolution(test), pass = true;
 for (var prop in test)
        if (test.hasOwnProperty(prop))
            if (results[prop] !== test[prop]) pass = false;
 alert(pass ? "PASS" : "FAIL") }());
0
source

All Articles