JavaScript - instanceof not doing what I expect

Viewed 58

Forgive me if I'm wrong, but I thought that by doing this:

function MyObject()
{
    return {
        key: 'value',
        hello: function() { console.log('world'); }
    };
}

var obj = new MyObject();

I create a new instance of the MyObject type.

However, if I do this:

obj instanceof MyObject

It returns false. This baffles me, as I thought that this would return true.

What am I doing wrong here?

Here's a fiddle that tests this.

I thought that I new the basics of JavaScript, but perhaps not. However, I've found sources that contradict my findings.

1 Answers
Related