如何快速将字符串false转换为布尔类型

  1. JSON.parse('false')

Object对象默认对key执行toString()

  1. const a = {}
  2. const b = { key: 'b' }
  3. const c = { key: 'c' }
  4. const d = [1,3,5,7]
  5. // Object.prototype.toString().call(b) => '[object Object]'
  6. a[b] = 123 // a['[object Object]'] = 123
  7. a[c] = 456
  8. // [1,3,5,7].toString() => 1,3,5,7
  9. a[d] = 789 // a['1,3,5,7'] = 789
  10. // a => { '[object Object]': 456, '1,3,5,7': 789 }

js写一个链式调用的函数

  1. // Print().Print()() => bbbb
  2. // Print()().Print() => aaa
  3. function Print() {
  4. // typeof print => function
  5. // function是Object类型,可以对它增加属性 => print.Print = function() {}
  6. const print = function() {
  7. return {
  8. Print:function() {
  9. console.log('aaa')
  10. }
  11. }
  12. }
  13. print.Print = function() {
  14. return function() {
  15. console.log('bbbb')
  16. }
  17. }
  18. return print
  19. }