Skip to content

Instantly share code, notes, and snippets.

@loveyunk
Created November 18, 2018 05:18
Show Gist options
  • Save loveyunk/1ccbd307deec93e7c28ca1993e6b22d4 to your computer and use it in GitHub Desktop.
Save loveyunk/1ccbd307deec93e7c28ca1993e6b22d4 to your computer and use it in GitHub Desktop.
<!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