Skip to content

Instantly share code, notes, and snippets.

@mixj93
Created February 21, 2020 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mixj93/9719965db738c64446cd67602bda0a47 to your computer and use it in GitHub Desktop.
Save mixj93/9719965db738c64446cd67602bda0a47 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/kaxijeq
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
var myObj = {
value: 0
}
myObj.increase = function(step) {
this.value += typeof step === 'number' ? step : 1
}
myObj.double = function() {
this.value = this.value * 2
}
myObj.double2 = function() {
var that = this
var helper = function() {
console.log(this)
console.log(that)
}
helper()
}
myObj.increase()
console.log(myObj.value)
myObj.double()
console.log(myObj.value)
myObj.double2()
</script>
<script id="jsbin-source-javascript" type="text/javascript">var myObj = {
value: 0
}
myObj.increase = function(step) {
this.value += typeof step === 'number' ? step : 1
}
myObj.double = function() {
this.value = this.value * 2
}
myObj.double2 = function() {
var that = this
var helper = function() {
console.log(this)
console.log(that)
}
helper()
}
myObj.increase()
console.log(myObj.value)
myObj.double()
console.log(myObj.value)
myObj.double2()</script></body>
</html>
var myObj = {
value: 0
}
myObj.increase = function(step) {
this.value += typeof step === 'number' ? step : 1
}
myObj.double = function() {
this.value = this.value * 2
}
myObj.double2 = function() {
var that = this
var helper = function() {
console.log(this)
console.log(that)
}
helper()
}
myObj.increase()
console.log(myObj.value)
myObj.double()
console.log(myObj.value)
myObj.double2()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment