- Programming content overview
- Tracking progress of programming students
- Classroom debugging guide
- Pair programming in the classroom
- Teaching guide: Intro to JS - Drawing Basics
- Teaching guide: Intro to JS - Coloring
- Teaching guide: Intro to JS - Variables
- Teaching guide: Intro to JS - Animation basics
- Teaching guide: Intro to JS - Interactive Programs
- Teaching guide: Intro to JS - Resizing with variable expressions
- Teaching guide: Intro to JS - Text and strings
- Teaching guide: Intro to JS - Functions
- Teaching guide: Intro to JS - Logic and if statements
- Teaching guide: Intro to JS - Looping
- Teaching guide: Intro to JS - Arrays
- Teaching guide: Intro to JS - Objects
- Teaching guide: Intro to JS - Object-oriented design
- Programming classroom handouts
- Additional programming projects
- Lesson plans: teaching programming in the classroom
- Programming case study: Encouraging cross-disciplinary projects
- Programming case study: Going beyond the KA curriculum
- Programming case study: Teaching an elementary school class
What the student will learn
- How to define methods on objects, so that all instances share the same methods.
- How to define an object that inherits from another object, so that it can reuse parent methods but also its own new methods.
The student will be able to write code like:
Where students struggle
- Students may wonder why object-oriented programming is so important and whether it's worth the difficulty in learning it. OO is a technique that gets more important as programs get bigger and more complex, and it’s particularly useful for the types of programs that are popular on Khan Academy - like games and natural simulations. Those programs all involve objects conceptually - like obstacles and avatars in games, or particles and emitters in simulations. It’s possible to write the programs using just functions, but it’s often easier to write them using object-oriented code, because then you can easily re-use similar functionality in similar objects.
- Students often find the
thiskeyword confusing. That’s the keyword that an object used to refer to itself - in other languages, it’s actually
me. It’s necessary to use this to tell an object to find a variable that’s a property on itself, instead of a local or global variable.
- Students get confused between the object definition and object instances. One thing that helps is if they pay attention to capitalization, as we use that to distinguish. We use capital letters to define an object type, like
Winston, and lowercase when we create instances, like
winstonAdult. Remind them that the first step is to define the object type (
Winston) and only then can they create new instances based on that type (
- Students might accidentally define object methods before their object constructor. The object constructor must be first, and then the methods.
Additional materials: Discussion questions
These are questions that you can ask students individually after they've done the lesson, or lead a group discussion around, if everyone's gotten to the same point.
- Discuss how you would program the concept of animals using OO programming. What properties and methods would you define on an Animal object? What objects would inherit from Animal, and what properties and methods would they have? You can have that same discussion about other objects as well, like Cars, Trees, Books, Shapes. There's no right answer, as the actual way you'd code it would depend on the app/game, but it's a useful exercise in thinking about object attributes, behavior, and inheritance.