symbol.js 321 B

1234567891011121314151617
  1. /**
  2. * 对于ES6中Symbol的极简兼容
  3. * 方便模拟私有变量
  4. */
  5. let Symbol = window.Symbol
  6. let idCounter = 0
  7. if (!Symbol) {
  8. Symbol = function Symbol(key) {
  9. return `__${key}_${Math.floor(Math.random() * 1e9)}_${++idCounter}__`
  10. }
  11. Symbol.iterator = Symbol('Symbol.iterator')
  12. }
  13. window.Symbol = Symbol