Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions _posts/2014-07-09-javascript-constructor-problem.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ snafu.concatenated()
//=> 'Situation Normal All Fsked Up'
{% endhighlight %}

Now it works, but of course `snafu` is an instance of `Fubar`, not of `LoggingFubar`. Is that what you want? Who knows!? This isn't a justification for the pattern, as much as an explanation that it is a useful, but leaky abstraction. It's doesn't "just work," but it can make certain things possible (like decorating constructors) that are otherwise even more awkward to implement.
Now it works, but of course `snafu` is an instance of `Fubar`, not of `LoggingFubar`. Is that what you want? Who knows!? This isn't a justification for the pattern, as much as an explanation that it is a useful, but leaky abstraction. It doesn't "just work," but it can make certain things possible (like decorating constructors) that are otherwise even more awkward to implement.

### solution: overload its meaning

Expand Down Expand Up @@ -253,4 +253,4 @@ var arrayOfSevereProblems = problems.filter(Fubar.is);

There you have it: Constructors that fail when called without `new` are a potential problem, and three solutions we can use are, respectively, auto-instantiation, overloading the constructor, or killing such calls with fire.

(discuss on [reddit](http://www.reddit.com/r/javascript/comments/2acr9f/a_javascript_constructor_problem_and_three/))
(discuss on [reddit](http://www.reddit.com/r/javascript/comments/2acr9f/a_javascript_constructor_problem_and_three/))