addyosmani / addyosmani/essential-js-design-patterns

Decorator Pattern extend()

Open
#222 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
HTML
Stars
4.9k
Forks
804
PR merge metrics
No merged PRs in 30d

Description

Hi Addy,

I wonder why in this line of code https://github.com/addyosmani/essential-js-design-patterns/blob/21346c134aa953ba469782372c90e42c36a1f083/book/snippets/01-JavaScript-Design-Patterns/12-the-decoration-pattern.es5.js#L255 we are extending `CaseDecorator` with `MacbookDecorator`. As functions, they don't have any enumerable properties by their own yet. Shouldn't happen the extension in the prototype like:

`extend(CaseDecorator.prototype, MacbookDecorator.prototype);`

because trying to do this `console.log(decoratedMacbookPro.addEngraving());` results in a `TypeError: decoratedMacbookPro.addEngraving is not a function`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.