2

What I think this is doing is looking to see if this object has already been instantiated and exists within the scope? Why do we need to use a triple equal sign to determine?

   function viewmodel(parent) {

            if (false === (this instanceof viewmodel)) {
                return new viewmodel(parent);
            }

    };
PythonIsGreat
  • 7,529
  • 7
  • 21
  • 26

2 Answers2

6

You don't need a strict equality comparison there. instanceof yields true or false, so this is entirely sufficient:

if (!(this instanceof viewmodel))
JMM
  • 26,019
  • 3
  • 50
  • 55
3

The triple equals prevents implicit datatype conversion.

See this question for more information.

Community
  • 1
  • 1
Pudd
  • 449
  • 3
  • 13
  • 4
    There's no conversion between `boolean` and `!boolean`. – JMM Apr 29 '15 at 12:37
  • 3
    In this case, no. I gave this answer for completeness sake, as the OP asked about the triple equals sign specifically. As other answers have mentioned, it is somewhat superfluous. In other comparisons, it could have significance, as seen in the linked question. – Pudd Apr 29 '15 at 12:40