Manny's Objects

node v7.10.1
version: master
endpointsharetweet
//how to create a class with the keyword class // 1. type the class key word and the name of your class the name of the class // 2. Use the constructor function list the properies you want the class to have(inside the parentheses) // 3. inside of your constructor (between the brackets) set the initial values of each property with the following syntax this.whatever = whatever or this.whatever = 'default value' // if you use a default value you will always have the value for the property unless you explicitly change it when you instantiate it // 4. declate a new variable // 5. set the value = to new NameOfClass('inside', 'here', 'give the properties their values') // 6. play around with the class below. // 7 this is synatically the same as what Kevin is showing and the way he is showing it is more common in normal javascript class Person { constructor(firstName, lastName, age, city, occupation) { this.firstName = 'Manny' this.lastName = lastName this.age = age this.city = city this.occupation = occupation } goesToWork() { } } const manny = new Person('Hagman', 21, 'Austin', 'Professional Football Player') function CoolPerson(firstName, lastName, age, city, occupation) { this.firstName = firstName this.lastName = lastName this.age = age this.city = city this.occupation = occupation } const bill = new CoolPerson('William', 'Clinton', 60, 'Little Rock', 'Ex President')
Loading…

no comments

    sign in to comment