我很尴尬地问这么简单的问题.我的任期不会再开始两周,所以我不能问一位教授,这个悬念会杀了我.
为什么2 mod 4 = 2?
我正在尝试遍历嵌套对象以检索由字符串标识的特定对象.在下面的示例对象中,标识符字符串是"label"属性.我无法绕过如何遍历树以返回适当的对象.任何帮助或建议将不胜感激.
var cars = {
label: 'Autos',
subs: [
{
label: 'SUVs',
subs: []
},
{
label: 'Trucks',
subs: [
{
label: '2 Wheel Drive',
subs: []
},
{
label: '4 Wheel Drive',
subs: [
{
label: 'Ford',
subs: []
},
{
label: 'Chevrolet',
subs: []
}
]
}
]
},
{
label: 'Sedan',
subs: []
}
]
}
Run Code Online (Sandbox Code Playgroud) 我理解在流行的JavaScript库(如jQuery和Prototype)中使用(单个)美元符号.我也理解PHP(变量变量)中双美元符号的重要性.Dean Edwards在他着名的addEvent() JavaScript函数中使用了双美元符号.这是一个包含使用双美元符号的除外:
function addEvent(element, type, handler) {
// assign each event handler a unique ID
if (!handler.$$guid) handler.$$guid = addEvent.guid++;
// create a hash table of event types for the element
if (!element.events) element.events = {};
// create a hash table of event handlers for each element/event pair
var handlers = element.events[type];
if (!handlers) {
handlers = element.events[type] = {};
// store the existing event handler (if there is one)
if (element["on" + type]) {
handlers[0] = element["on" …Run Code Online (Sandbox Code Playgroud)