# Week 2 - Cordova Android, Classes, ENV

# JavaScript is a Prototype Based Language

You will hear a lot about prototype and class over the next few semesters. They are two different approaches to designing and architect software. The problem is that in your early days of programming they can seem like almost the same thing. To be fair, they are quite similar and they are two solutions that solve the same problem.

We will try to help you understand the differences here in simple practical terms that will let you write better JavaScript with fewer unexpected errors.

A Class is a blueprint for building objects. It is not an object itself, just the plans for building a certain kind of object. Classes inherit properties and methods from parent classes. When you create (instantiate) an object from a class, the object will be given copies all the properties and methods from it's class blueprint as well as copies of all the properties and methods from all the ancestor parent classes. So, when you call an Object's method, the method actually exists inside the Object.

A prototype is an example Object. It is an Object. Think of it as the first one built. In JavaScript, when we create an Object a constructor function is used to build the object. That function has a prototype object. We can put any methods that we want to share with all the objects built with that constructor into that prototype object. We can still link our objects to parent ones but we don't copy the methods, instead, we just link to the parent's prototype. There is a chain of prototype type objects. When we create (instantiate) our Object, it doesn't need copies of all the methods and parent methods. If we call an Object's method and the method does not exist inside our Object, then JavaScript will look up the prototype chain for the method and delegate (borrow) the method to run.

Learn more about Prototype

# Classes

JavaScript, as we have discussed, is a prototype based language, not a class based language. However, there was a keyword class added to JavaScript in ES6. Along with the class keyword a few other keywords were added: extends, constructor, static, get, set, and super. Many of these will be familiar to you from your OOP course.

It is important to remember that these words are just syntactic sugar. JavaScript is still using prototypes behind the scenes. These terms were created as a simplified syntax for creating the prototypes and the prototype chain.

Learn about the JavaScript Class Keyword

# this keyword

The JavaScript version of the keyword this works differently than in true class-based languages. In JS, it also changes what it means and how it works, depending on the context and where you use it.

Learn more about keyword this

# Cordova on Android and ENV variables

Last week we covered all the fundamentals of installing, setting up and running Cordova, as well as the iOS specific requirements for Cordova.

This week we will be talking about the extra steps for running Cordova for Android.

CodePen Cordova Command list (opens new window) - this is a list of the commands that you can use to manage any Cordova project, including the iOS and Android specific tasks.

Learn more about the Cordova Android specifics

Last semester, in MAD9012, you learned how to create and edit Environment variables through your ~/.zshrc file on the MacOS side and through Windows Properties on the Windows side.

Make sure that you update your ~/.zshrc file with the new PATH value for the new global install location for NPM.

Review the course website notes for MAD9012 for more instructions on how to do this.

TODO

  • Read the content and watch the videos for Week 2 and Week 3
  • Prepare for the second timed exercise
  • Review the description for the first Cordova project.
Last Updated: 1/19/2021, 7:28:13 PM