Last active
March 27, 2016 16:41
-
-
Save alexnm/606c02e9806b75f3042f to your computer and use it in GitHub Desktop.
Example of object creation through object literal
This file contains 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
const product = { | |
name: 'T-Shirt', | |
price: 9.99, | |
color: 'red', | |
size: 'M', | |
stock: 4, | |
updateStock: function( newStock ) { | |
this.stock += newStock; | |
} | |
}; | |
console.log( product.stock ); // 4 | |
product.updateStock( 3 ); | |
console.log( product.stock ); // 7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment