Advertisement
DigitalMag

ts/js context problem on replace (resolves b bind, but fact)

Jul 22nd, 2020
1,596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Cls {
  2.   constructor() {
  3.    
  4.   }
  5.   replacer () {
  6.     console.log(this)
  7.     return '6'
  8.   }  
  9.   func(){
  10.     console.log(JSON.stringify(this))
  11.     var r = '123456'.replace(/1/g, this.replacer)
  12.     console.log(r)
  13.   }
  14. }
  15.  
  16.  
  17. var ex = new Cls()
  18.  
  19. ex.replacer()
  20. ex.func()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement