0

I have a JS object as follows:

var actType = {
    form  : $form,
    input : "select[name='journalEntry.activityType']",
    valid : $form.find("select[name='journalEntry.activityType']").val() === "",
    errorClass: "sr-error-task",
    errorMessage: "Please select a task."
};

My questions are:

  1. Is it possible to reference the $form value in the actType.valid parameter with actType.form?
  2. Would the first actType.form = "test" and the second actType = "pass" considering this code?

For example:

$form = "test";
var actType = {
    form  : $form,
    input : "select[name='journalEntry.activityType']",
    valid : $form.find("select[name='journalEntry.activityType']").val() === "",
    errorClass: "sr-error-task",
    errorMessage: "Please select a task."
};

$form = "pass";
actType = {
    form  : $form,
    input : "select[name='journalEntry.activityType']",
    valid : $form.find("select[name='journalEntry.activityType']").val() === "",
    errorClass: "sr-error-task",
    errorMessage: "Please select a task."
};
jww
  • 97,681
  • 90
  • 411
  • 885
newbie
  • 14,582
  • 31
  • 104
  • 146
  • 3
    correct me if I'm wrong, but you're making `$form` a string, then you're referencing it as a string, then as a jQuery object? – Kevin Pei Feb 12 '14 at 03:25
  • To correct your terminology, this question has nothing to do with JSON (JavaScript Object **Notation**). You have a JavaScript **object**. JSON refers to a string with formatting the same as JavaScript Object declaration syntax. – Travesty3 Feb 12 '14 at 03:27
  • 1) No, actType is undefined until the statement is completed, so actType.form will be an access error. 2) Yes, standard JavaScript. – Stephen Chung Feb 12 '14 at 03:28
  • @Travesty3, I think this question is relevant to JSON as he is asking what values the resultant object takes on with different JSON formulations. – Stephen Chung Feb 12 '14 at 03:29
  • this is a js object... – newbie Feb 12 '14 at 03:31
  • @StephenChung: There's no JSON here. It's a JS object. – Travesty3 Feb 12 '14 at 03:31
  • @StephenChung—there is no JSON here. According to ECMA-262 what he OP has is an [object initializer](http://ecma-international.org/ecma-262/5.1/#sec-11.1.5), also known as an object literal (though it is strictly not a [literal according to the spec](http://ecma-international.org/ecma-262/5.1/#sec-7.8)). – RobG Feb 12 '14 at 03:32
  • Doh! You're right. It is an object initializer, not JSON. Although the syntax is similar (as JSON is based on JS's object initializer syntax) – Stephen Chung Feb 12 '14 at 05:06

0 Answers0