Skip to content

Instantly share code, notes, and snippets.

@ludofleury
Last active March 25, 2021 01:22
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 ludofleury/c1a9a93e74de4dd645351d04782b2321 to your computer and use it in GitHub Desktop.
Save ludofleury/c1a9a93e74de4dd645351d04782b2321 to your computer and use it in GitHub Desktop.
Attribute & Method vs Variable & Function
//////////// Object oriented programming
console.log('Calculator:');
let calculator = {
// attribute "result" of calculator object
result: 0,
// method "add()" of calculator object
add: function (number) {
this.result += number;
},
}
calculator.add(2)
calculator.add(5)
console.log(calculator.result);
////////////// Functionnal programming
console.log('Function:');
// function "add()""
function add(number1, number2) {
return number1 + number2;
}
// variable "result"
let result = 0;
result = add(result, 2)
result = add(result, 5);
console.log(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment