Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
class CancelToken {
  reason = ''
  constructor(executor) {
    console.log('executor = ', executor)
    executor(message => {
      console.log('message', message)
      if (this.reason) return
      this.reason = message
    })
  }
}
let cancel;
function fn(c){
  console.log('c = ', c)
  cancel = c
}
function fn2(message) {
  console.log('message', message)
  if (this.reason) return
  this.reason = message
}
// new CancelToken(fn)
// cancel()
fn(fn2) // 注意此时 fn2 并没有被调用
// fn2 什么时候才会被调用? 因为 c === fn2
// 只有当 c 调用,fn2 才会被调用
cancel()
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers