Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="ES6 箭頭函式 demo2">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
// 原本的 function
let fn = function(){
  console.log(this.constructor.name);  // Object(data)
  setTimeout(function(){
    console.log(this.constructor.name) // Window
  },100);
}
// 箭頭函示 Arrow function
let fn_arr = function(){
  console.log(this.constructor.name);  // Object(data)
  setTimeout(() => {
    console.log(this.constructor.name) // Object(data)
  },100);
}
let id = 21;
let data = {
  id: 21
}
fn.call(data);     // Window
fn_arr.call(data); // Object(data)
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
PJCHENderpro
0viewers