Calling an object method from an object property definition

Posted by Ian on Stack Overflow See other posts from Stack Overflow or by Ian
Published on 2011-01-01T23:29:44Z Indexed on 2011/01/01 23:54 UTC
Read the original article Hit count: 204

Filed under:

I am trying to call an object method from an object (the same object) property definition to no avail.

var objectName = {
     method   :   function() {
          return "boop";
     },
     property :   this.method()
};

In this example I want to assign the return value of objectName.method ("boop") to objectName.property.

I have tried objectName.method(), method(), window.objectName.method(), along with the bracket notation variants of all those as well, ex. this["method"], with no luck.

© Stack Overflow or respective owner

Related posts about JavaScript