(function() { // Inertia's Function Module V2 [www.khanacademy.org/cs/_/5415663367127040] // Function Module adds to the Native Function Object Define(["Func", "Function", "Fn"], function() { var Core = require("Core"), Util = require("Util"), _ = Util._, MapFunc = Util.MapArr, Native = Core.Func, $Map; // Map Of Names And Functions $Map = [ [["args"], Util.args], // Turn the Arguments Object into an Array [["new"], Util.new], // A more efficient `new` // Empty / Noop / Dummy function [["empty", "noop", "dummy"], Native()], // List all the Names of a Functions Arguments [["argNames"], function(fn) { var args = fn.toString() .match(/^[\s\(]*function[^(]*\(([^)]*)\)/)[1] .replace(/\/\/.*?[\r\n]|\/\*(?:.|[\r\n])*?\*\//g, '') .replace(/\s+/g, '').split(','); return args.length === 1 && !args[0] ? [] : args; }], // Remove extra code in a Stringifed Function [["toStr"], function(fn) { var $fn = fn.toString().trim() .replace(/(__)env__\.\$(\w+) = /g, "const $$$2 = ") .replace(/(__)env__\.\$(\w+)/g, "$$$2") .replace(/var\s+\$(\w+)/g, "const $$$1") .replace(/(__)env__\.KAInfiniteLoopProtect\(.*\);/g, "") .replace(/(__)env__\.KAInfiniteLoopCount = 0;/g, "") .replace(/(__)env__\.KAInfiniteLoopCount > 1000/g, "") .replace(/(__)env__\.KAInfiniteLoopCount\+\+;\s+if \(\) {\s+}\n/g, "") .replace(/(__)env__\.KAInfiniteLoopSetTimeout\(\d+\);\n/g, "") .replace(/__env__\./g, ""), copy; copy = $fn.replace(/{\s+/g, '{ ').replace(/\s+}/, " }"); return $fn.match(/[\n]/g).length <= 2 ? copy : $fn; }] ]; // Extend Methods _.extend(Native, MapFunc(Native, $Map)); _.extend(Native.prototype, MapFunc(Native.prototype, $Map, true)); return Native; }, true); })(); // Function