好好爱自己!

ES6 中 Symbol.split的用法

class Split1 {
  constructor(value) {
    this.value = value;
  }
  [Symbol.split](string) {
    var index = string.indexOf(this.value);
    return this.value + string.substr(0, index) + "/"
      + string.substr(index + this.value.length);
  }
}

console.log('foobar'.split(new Split1('foo')));
// expected output: "foo/bar"

  原文: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/split

posted @ 2018-10-09 18:05  立志做一个好的程序员  阅读(890)  评论(0编辑  收藏  举报

不断学习创作,与自己快乐相处