const solution = new RegExp('.'); var str = solution.test.toString(); solution.test = function(x) { /* тут любое решение )) */ }; solution.test.toString = function() { return str; };