Created
November 18, 2018 05:18
-
-
Save loveyunk/1ccbd307deec93e7c28ca1993e6b22d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Document</title> | |
</head> | |
<body> | |
<script> | |
// 箭头函数使函数内this转变为词法作用域 | |
// const Jelly = { | |
// name: 'Jelly', | |
// hobblies: ['Coding', 'Sleeping', 'Reading'], | |
// printHobblies: function () { | |
// this.hobblies.map(function (hobby) { | |
// console.log(`${this.name} loves ${hobby}`) | |
// }) | |
// } | |
// } | |
// Jelly.printHobblies() | |
const Jelly = { | |
name: 'Jelly', | |
hobblies: ['Coding', 'Sleeping', 'Reading'], | |
printHobblies: function () { | |
this.hobblies.map(hobby => console.log(`${this.name} loves ${hobby}`)) | |
} | |
} | |
Jelly.printHobblies() | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment