获取JavaScript对象文字中键的同级值 [英] Getting sibling value of key in a JavaScript object literal

查看:100
本文介绍了获取JavaScript对象文字中键的同级值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道有一种方法可以在JavaScript对象文字中引用同级键的值吗?

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

因此请在此处的beforeNext()函数中使用target的值:

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');
        }
      }

推荐答案

这不是"JSON"对象,而是JavaScript对象(或仅仅是"Object").我认为这也包含在对象文字中,因为obj: {本身是无效的语法.

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.

无论如何,是的,您可以使用this在方法中引用对象的属性.

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

beforeNext: function () {
    this.target;
}

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

这篇关于获取JavaScript对象文字中键的同级值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆