Menu

Prototype syntax is still useful. Under certain conditions
🖼️

Prototype syntax is still useful. Under certain conditions

DEV Community·Beey·5 months ago
#bGUObcgv
#why#webdev#javascript#programming#syntax
Reading 0:00
15s threshold

What is prototype syntax

Prototype syntax is still useful.

Before ECMAscript 6 the class keyword did not exist so developers had to use prototype syntax:

function Name ( params ) { this . name = value ; // ... }

ClassName . prototype . name = function ( params ) { // ... }

// ...

Enter fullscreen mode

Exit fullscreen mode

That was prototype syntax.

why is it still useful

If you are using a legacy environment where ECMAscript 6 doesn't exist. That's when prototype syntax becomes useful.

Prototype syntax is in commonJS so you can use this in CJS(CommonJS) scripts.

NOTE : modern CommonJS supports class so prototype syntax is still legacy by definition

Why class exists

class exists to make OOP(Object Oriented Programming) easier.

Protoype syntax altho useful, is more complex and lengthy to use. even with minification

it also introduced the constructor keyword

classes introduced getters and setters

with the new class syntax you can now use:

class name { constructor ( params ) { this .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.