(function($){ var _Game_Interpreter_pluginCommand = $.prototype.pluginCommand; $.prototype.pluginCommand = function(command, args) { _Game_Interpreter_pluginCommand.call(this, command, args); if (command === "test"){ // remove .s and replace with whitespace var _str = args[0].replace(/[\.*]/g, " "); // check for newline character and replace with newline character _str = _str.replace(/\\n*/g, "\n"); console.log(_str); // has the expected result }; }; })(Game_Interpreter)