JavaScript has a ‘new’ operator for creating objects. Each object in JavaScript has a hidden pointer to a prototype object, from which it inherits properties. This pointer is set when the object is created, and cannot be changed during the lifetime of the object.

When ‘new’ is used, an object is created that has other than the usual default Object prototype object.

From ‘new’ we can define a function create(proto) that returns an object whose prototype object is ‘proto’. (I first saw this in Douglas Cockcroft’s book JavaScript: The Good Parts, but he calls it ‘beget’.)

Conversely, from ‘create’ we can define a function, say ‘New’ that has the same functionality as the ‘new’ operator. (In JavaScript ‘new’ is a keyword, whose meaning can be changed.)

The ‘create’ operator is in some sense simpler than the ‘new’ operator, but each can be defined in terms of the other. According to Wikipedia, syntactic sugar “is syntax designed to make things easier to read or to express, while alternative ways of expressing them exist”.

I think ‘create’ is simpler to use and understand than ‘new’, and so I don’t regard it as syntactic sugar for the creation creation of objects.  The same Wikipedia term also suggests the term  syntactic saccharin for gratuitous syntax which does not actually make programming easier.  I consider ‘new’ to be syntactic saccharin.

Advertisements