Skip to content

Instantly share code, notes, and snippets.

@Grubba27
Created February 17, 2023 21:52
Show Gist options
  • Select an option

  • Save Grubba27/da7cfbd27671b2682cd1c7d8ef6a9808 to your computer and use it in GitHub Desktop.

Select an option

Save Grubba27/da7cfbd27671b2682cd1c7d8ef6a9808 to your computer and use it in GitHub Desktop.
arrow vs function declaration
const Module = {
value: 0,
someFn: () => {
return this.value;
},
okayFn() {
return this.value;
}
}
class Module2 {
value = 0;
someFn = () => {
return this.value;
}
okayFn() {
return this.value;
}
}
console.log(
{
ModuleValues:
{
someFn: Module.someFn(),
okayFn: (Module.add(),Module.okayFn()),
},
Module2Values:
{
someFn: new Module2().someFn(),
okayFn: new Module2().okayFn(),
}
}
)
It returns //
/*
{
"ModuleValues": {
"someFn": null,
"okayFn": 0
},
"Module2Values": {
"someFn": 0,
"okayFn": 1
}
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment