Created
March 18, 2018 14:12
-
-
Save jsmayo/14bd15e915878c9f99dd9a31a8ada847 to your computer and use it in GitHub Desktop.
staticMethods.js created by jsmayo - https://repl.it/@jsmayo/staticMethodsjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
count = 0; | |
class Person { | |
constructor(firstName, lastName, favoriteColor, favoriteNumber) { | |
this.firstName = firstName; | |
this.lastName = lastName; | |
this.favoriteColor = favoriteColor; | |
this.favoriteNumber = favoriteNumber; | |
} | |
multiplyFavoriteNumber(num) { | |
return num * this.favoriteNumber; | |
} | |
static countIterator() { | |
count++; | |
console.log(count); | |
} | |
} | |
// Static methods can be called without the object being created | |
Person.countIterator(); | |
// Making a new Person Object | |
var a = new Person("first", "last", "yellow", 16); | |
// Looking at current properties | |
console.log(a); | |
// Call static method | |
Person.countIterator(); | |
/* Note | |
Cannot do a.countIterator() and using a.countIterator | |
will add the property countIterator to the 'a' object. */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment