Skip to content

Instantly share code, notes, and snippets.

@nazrievfarrukhjon
Created January 21, 2020 10:12
Show Gist options
  • Save nazrievfarrukhjon/42a7627ef75f92648b75e8ee4b54d8e6 to your computer and use it in GitHub Desktop.
Save nazrievfarrukhjon/42a7627ef75f92648b75e8ee4b54d8e6 to your computer and use it in GitHub Desktop.
js context
<html>
<script>
class Main {
constructor () {
this.name = "Name in class"
this.person = {
name: "Alisher",
getName: function () {
return this.name
}
},
this.person2 = {
name: "Chuvak",
getName: () => {
return this.name
}
}
}
returnPerson1 () {
console.log(this.person.getName())
}
returnPerson2 () {
console.log(this.person2.getName())
}
}
let main = new Main()
main.returnPerson1()
main.returnPerson2()
// ------------------------
window.name = "Name in window"
function mainFunction () {
const name = "name in function"
const someOne = {
name: "Some one 1 name",
getName: function () {
return this.name
}
}
console.log(someOne.getName())
const someOne2 = {
name: "Some one 2 name",
getName: () => {
return this.name
}
}
console.log(someOne2.getName())
}
mainFunction()
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment