From the below code one can discern that the function menu is called with three parameters.
From the menu function how could one get name or diff name depending on which had called menu?
var menus = {
name: menu('Control', [
{
label: 'Public Class My Robot',
trigger: true,
script: 'public class MyRobot extends SimpleRobot\n{\n[[next]]\n}\n',
helptext: "Beginning fo your program",
depend: "package edu.team2648.frcEasyJ;"
}], false),
diffname: menu('Control2', [
{
label: 'Public Class My Robot',
trigger: true,
script: 'public class MyRobot extends SimpleRobot\n{\n[[next]]\n}\n',
helptext: "Beginning fo your program",
depend: "package edu.team2648.frcEasyJ;"
}], false),
};
Also what kind of var is menus? (Array, Object,…?)
What is the difference between the following two snippets of code:
var test = ["str1","str2","str3","str4"];
var test2 = {id:"str1",id2:"str2",id3:"str3",id4:"str4"};
Since there are no associative arrays in JavaScript, you need to use objects if you want to assign key:val pairs and simulate the associative array functionality and reference behavior.
var test = ["str1","str2","str3","str4"];signifies a numerically-indexed array. We see the square brackets which groups the array, and we only see comma delimited values. If we wanted to access ‘str3’ we’d usetest[2].var test2 = {id:"str1",id2:"str2",id3:"str3",id4:"str4"};is an object. We see the curly braces which groups the object parameters, and we can see the key:val pairs split by the colon. If we want to access ‘str3’, we’d usetest2.id3One thing that might be confusing to beginners is that objects can contain arrays and arrays can contain objects, so the square brackets and curly braces can be mixed in and not be immediately obvious. You can create an array through the Array object like
var arr = new Array(). To keep things simple, segregate them and call them by their intended behavior:[]= array, and{}= object.In your example:
You can see that
menusis an object because it’s assigned to a curly brace. You can see thatnameis a key andmenu('Control'is a value, which happens to be a function in this case. It’s first parameter is an obvious string, and it’s second is an array[]which only contains one value, which is an object{}which has key:val pairs –labelbeing the key, and'Public Class My Robot'being the value which is simply a string in this case.