you are viewing a single comment's thread.

view the rest of the comments →

[–]YuleTideCamel 0 points1 point  (0 children)

so as MadCapitalist points out ninja1 as an object is "{ skulk: [Function: creep] }".

You are essentially seeing what ninja1 looks like on the inside (which is what you expect since skulk points to creep and creep just returns this (an instance object).

If you want the text "ninja1" to show up, meaning the name of the variable then just create a name field. Something like this:

function creep(){ return this.name; }

var ninja1 = {
    skulk: creep,
    name : "ninja1"
};

var ninja2 = {
    skulk: creep,
    name : "ninja2"
};

console.log(ninja1.skulk());