Skip to content

Instantly share code, notes, and snippets.

View paulbuis's full-sized avatar
💭
Teaching a Programming Language class at Ball State University

Paul Buis paulbuis

💭
Teaching a Programming Language class at Ball State University
View GitHub Profile
@paulbuis
paulbuis / 0 - JavaScript (ES6) Singly Linked List Class.md
Last active December 13, 2016 18:18
Basic Linked List Class in JavaScript to be used to support Stack operations (push/pop), later versions to support Queue operations

The file 1-list.js below shows how to declare a OO-style class in JavaScript.

Note that the only things assigned to properties of this are anonymous functions. These are the "methods" of the class that access "private" properties. JavaScript doesn't have the keyword private like some other languages. Instead, the "private data members" of a class are the local variables and parameters of the class constructor. Most JavaScript code in the wild doesn't attempt to make anything "private" which is just bad OO design. Here, the "methods" are functions nested inside the constructor to give them access to the constructors local variables.

Typical JavaScript code you see in the wild would have placed the methods as properties of List.prototype which allows for