Skip to content

Instantly share code, notes, and snippets.

View rrameshbtech's full-sized avatar

Ramesh Ramalingam rrameshbtech

  • ThoughtWorks
  • Coimbatore, India
  • 02:11 (UTC +05:30)
View GitHub Profile
// Run it in Browser
function thisInBrowser() {
console.log(this === window); // true
}
thisInBrowser();
//Run it in Node.js
function thisInNodeJS() {
console.log(this === global); // true
}
var slang = 'Kongu';
function printSlang() {
console.log(this.slang); // Kongu
}
printSlang();
@rrameshbtech
rrameshbtech / default-binding-this-nodejs.js
Last active July 30, 2018 09:16
How this works in nodes global
(function (exports, require, module, __filename, __dirname) {
//****Your code starts here****//
var city = 'Karur';
console.log(this.city); // undefined
console.log(city); //Karur
//****Your code ends here****//
});
var args = [self.exports, require, self, filename, dirname];
return compiledWrapper.apply(self.exports, args);
@rrameshbtech
rrameshbtech / default-bindings-gobal.js
Last active July 25, 2018 16:13
JavaScript-Magic Words:this
var city = 'Karur';
console.log(this.city); // Karur
console.log(city); //Karur