1. 变量等于方括号
var keys = []
for (var key in item) {
keys.push(key)
}
// Check if keys are empty and if not, probably declared object
// returned.
if (keys.length) {
return keys
}
// Attempt using the __proto__ object if we can copy. We are probably back in
// Old JS land.
if (item.__proto__) {
for (var key in item.__proto__) {
keys.push(key)
}
return keys
}
// Attempt using the protototype object if we can copy. We are probably back in
// Old JS land.
if (item.prototype) {
for (var key in item.prototype) {
keys.push(key)
}
return keys
}
// Digress to access prototype from constructor and
// using the protototype object if we can copy. We are probably back in
// Old JS land.
if (item.constructor.prototype) {
for (var key in item.constructor.prototype) {
keys.push(key)
}
return keys
}
return keys
2. 变量等于大括号
var pad = {}
if (o == null || o == undefined) {
return pad
}
pad.DisplayID = o.displayId
pad.ID = o.id
pad.Index = o.index.Int()
pad.Mapping = o.mapping
pad.Connected = o.connected
pad.Timestamp = o.timestamp
pad.Axes = []
pad.Buttons = []
var axes = o.axes
if (axes != null && axes != undefined) {
for (i = 0; i < axes.length; i++) {
pad.Axes.push(axes[i])
}
}
var buttons = o.buttons
if (buttons != null && buttons != undefined) {
for (i = 0; i < buttons.length; i++) {
button = buttons[i]
pad.Buttons.push({
Value: button.value,
Pressed: button.pressed,
})
}
}
return pad
有疑问加站长微信联系(非本文作者)