Function as object methods
February 26, 2021
Homework
Asynchronous JS
JSON
fetch()
Reference
Morning reflection
Housekeeping
Assignment 3 Cancelled
CPNT 262 Assignment Review
1. FizzBuzz walkthrough
Learning Objectives
Review conditional statements: if
/else
/else if
.
Review arithmetic operators.
Test if a value is an integer.
Materials
Key Takeaways
There are usually many ways to solve a problem.
2. Functions as methods
Learning Objectives
Review object literals and how to initialize objects .
Demonstrate this
in the context of objects.
Refactor Tuesday’s Greeter function into an object.
Create an object method using an object literal and function expressions.
Terminology
Object
A collection of name/value pairs (in terms of Javascript)
Object Literal
An object literally coded using proper object notation.
Object Property
A fancy term for a name/value pair where the value is anything but a function.
Object Method
A fancy term for name/value pair where the value is a function.
this
(for methods)
When inside a method (a function that’s the property of an object), this
is a keyword that refers to the parent object.
Materials
Key Takeaways
Avoid the use of this
unless you’re working within a method (and not even inside a function inside a method). Outside of a method, this
is a big bag of hurt .
Open lab-time
Pick out a problem in the WBDV course website (that you think you can fix) and post an Issue about it. You will later fix this issue and create a Pull Request for CPNT 201 Assignment 4.
Tony’s goals for Lab-Time
Dailies
Submit today’s Codepen/repo/gist to the Dailies section (in Assessments) in Brightspace.
© 2021 Tony Grimes. MIT License.