Skip to content

Instantly share code, notes, and snippets.

@nishanbajracharya
Created September 26, 2018 13:57
Show Gist options
  • Save nishanbajracharya/be72358401195e6dd299f209e18ea2b8 to your computer and use it in GitHub Desktop.
Save nishanbajracharya/be72358401195e6dd299f209e18ea2b8 to your computer and use it in GitHub Desktop.
Getting around this;
var hello = document.getElementById('hello');
function Student(name, dob, el) {
var that = this;
this.name = name;
this.dob = dob;
this.el = el;
this.getProfile = function() {
console.log('In Get Profile', that);
return that.name + ' is an idiot';
}
this.getNameFiveTimes = function() {
var array = [];
console.log('In Get Name', that);
for (var i = 0; i < 5; i++) {
console.log(i, that);
array.push(that.name);
}
return array;
}
this.el.onclick = function() {
console.log('In onclick', that);
}
}
var john = new Student('John', '1990-01-02', hello);
console.log(john);
john.getProfile();
john.getNameFiveTimes()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment