Created
January 21, 2020 10:12
-
-
Save nazrievfarrukhjon/42a7627ef75f92648b75e8ee4b54d8e6 to your computer and use it in GitHub Desktop.
js context
This file contains 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
<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