The new keyword in JavaScript can sometimes slip up new and experienced programmers alike.
We typically associate this word with Classical-based Object-oriented languages (such as Java etc.), where as in JavaScript it works a little different.
Following on from my recent post on implementing a small RPN parser using JavaScript, we can expand on this by handling infix expressions.
This can be achieved by initially parsing the expression into its postfix (RPN) counterpart, highlighting another use case where a stack based approach works well.
Following on from our first screencast, which touched upon how to setup a PHP extension development environment and creating a simple ‘array_sum’ like function.
We now further this topic by implementing a resizable-indexed array class which supplies very similar functionality to that of the SplFixedArray class.
This morning I decided to quickly write up a small reverse polish notation evaluator in JavaScript.
Evaluation of these expressions highlights the perfect use case for a stack based approach.
I have always enjoyed how succinctly you are able to use commonly found operators as first-class functions in languages such as Clojure.
As a quick thought experiment I decided to see if it would be possible to use JavaScript’s capabilities to dynamically create functions, to mimic such behaviour.