Simplify method juggle in trim modules.

This commit is contained in:
John-David Dalton
2017-02-07 17:55:40 -08:00
parent 5e38259044
commit 8f8b29368e
3 changed files with 5 additions and 9 deletions

View File

@@ -4,8 +4,7 @@ import charsEndIndex from './.internal/charsEndIndex.js'
import stringToArray from './.internal/stringToArray.js'
import toString from './toString.js'
const stringProto = String.prototype
const nativeTrimEnd = stringProto.trimRight || stringProto.trimEnd
const methodName = ''.trimRight ? 'trimRight': 'trimEnd'
/**
* Removes trailing whitespace or specified characters from `string`.
@@ -28,7 +27,7 @@ const nativeTrimEnd = stringProto.trimRight || stringProto.trimEnd
function trimEnd(string, chars, guard) {
string = toString(string)
if (string && (guard || chars === undefined)) {
return nativeTrimEnd.call(string)
return string[methodName]()
}
if (!string || !(chars = baseToString(chars))) {
return string