Search code examples
javascriptkey-valueobject-literalsiblingscross-reference

Getting sibling value of key in a JavaScript object literal


Does anybody know of there's a way to reference the value of a sibling key in a JavaScript object literal?

so use the value of target in the beforeNext() function here:

obj: {
        target: 'li.player a.icon-tag',
        parent: 'ul#drop_list',
        beforeNext: function(){
          target.addClass('bind active');
        }
      }

Solution

  • This is not a "JSON" object, but a JavaScript Object (or just "Object"). I assume that this is also contained in an Object literal as obj: { by itself is invalid syntax.

    Anyway, yes you can reference properties of an object in methods with this.

    beforeNext: function () {
        this.target;
    }
    

    http://jsfiddle.net/ExplosionPIlls/Q9v8r/