Javascript prototypes
19th March 2003
Andrew Hayward (a friend from Uni who has recently started blogging) has been playing with javascript’s prototypes. prototype
is a value related to a particular class from which all instances of that class are created—only in javascript classes are actually functions... and then it all gets really complicated.
Anyway, Andy’s experiments concern using the prototype property to add new methods to javascript’s built in classes such as String, Array and even Object. He uses this trick to add useful methods such as String.trim()
, Array.implode()
and Object.dump()
. It looks remarkably useful both for debugging and for making javascript do more stuff in less lines of code by adding additional layers of abstraction to the core language.
We’ve been looking at javascript in our “Concepts of Programming Languages” course this semester and it’s proving a much more interesting language than I had originally thought.
More recent articles
- Qwen2.5-Coder-32B is an LLM that can code well that runs on my Mac - 12th November 2024
- Visualizing local election results with Datasette, Observable and MapLibre GL - 9th November 2024
- Project: VERDAD - tracking misinformation in radio broadcasts using Gemini 1.5 - 7th November 2024