Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Douglas Crockford on Class Free OOP in JavaScript

Douglas Crockford has a really good talk on "The Better Parts" of ES6. Among other things, he encourages a move away from prototypal inheritance in favor of class free OOP.

Here he says he stopped using new, Object.create, and this, but didn't really explain an alternative. Could anyone fill me in on how that might look?

like image 567
dpren Avatar asked Dec 22 '14 02:12

dpren


People also ask

Can you do OOP with JavaScript?

JavaScript is not a class-based object-oriented language. But it still has ways of using object oriented programming (OOP).

Is JavaScript good for learning OOP?

JavaScript may not be what comes to mind when someone mentions an OOP language, but the fact is it has great support for OOP - it just has its intricacies that need to be understood first.

What is class in OOP JavaScript?

JavaScript Classes. In JavaScript, classes are the special type of functions. We can define the class just like function declarations and function expressions. The JavaScript class contains various class members within a body including methods or constructor. The class is executed in strict mode.

What is Classin OOP?

In object-oriented programming , a class is a template definition of the method s and variable s in a particular kind of object . Thus, an object is a specific instance of a class; it contains real values instead of variables. The class is one of the defining ideas of object-oriented programming.


1 Answers

You should watch the whole video, he explains it at later in the video.

function constructor(spec) {   let {member} = spec,       {other}  = other_constructor(spec),       method   = function () {         // accesses member, other, method, spec       };    return Object.freeze({       method,       other   }); } 

It's the revealing module pattern returning a frozen object.

like image 145
Mathletics Avatar answered Oct 06 '22 01:10

Mathletics