re: Learning JavaScript Design Patterns VIEW POST

VIEW FULL DISCUSSION
 

Had a quick look at the "Creational Design Patterns".

You put these three together:

var newObject = {};
var newObject = Object.create(null);
var newObject = new Object();

Which would naturally mislead the readers to think they are equivalent. You should note that Object.create(null) do not inherit the Object.prototype.

There is also an error in the code example:

const defineProp = function(obj, key, value) {
    config.value = value; // config is not defined???
    Object.defineProperty(obj, key, config);
}

defineProp(newObject, 'someKey', 'Hello World');
 

Hi, thanks for the feedback! I've corrected said code snippet. Thanks for pointing that out.

As for your first concern. They indeed have some differences but I figured to just write something about it as a different topic. I should've gone first with that but my intention was first and foremost, to learn design patterns for myself. Right now, I'm just addressing JavaScript caveats that has something to do with design patterns context within JavaScript. Like defining a function within the function constructor versus via the prototype.

code of conduct - report abuse