es6.regexp.replace.js 495 B

123456789101112
  1. // @@replace logic
  2. require('./_fix-re-wks')('replace', 2, function (defined, REPLACE, $replace) {
  3. // 21.1.3.14 String.prototype.replace(searchValue, replaceValue)
  4. return [function replace(searchValue, replaceValue) {
  5. 'use strict';
  6. var O = defined(this);
  7. var fn = searchValue == undefined ? undefined : searchValue[REPLACE];
  8. return fn !== undefined
  9. ? fn.call(searchValue, O, replaceValue)
  10. : $replace.call(String(O), searchValue, replaceValue);
  11. }, $replace];
  12. });