Why they construct a function this way, what's the benefit

Hi guys,

I’ve run into a high performance canvas animation example and they code their script this way:

var Thingy = {};

Thingy.DOTHIS = 'doThis';
Thingy.DOTHAT = 'doThat';
Thingy.DOTHISANDTHAT = 'doThisAndThat';

Thingy.prototype = {
   a: function(x) {
   },
   doThis: ...
}

What is it called and what’s the term to search on Google. I’ve tried several keywords but I can’t find anything useful to start learning with.

Thank you,

If it’s the “Thingy” part you’re wondering about, it’s called the namespace pattern. It’s basically to avoid adding a bunch of global variables that could potentially clash with other scripts.

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.