-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolves #2247, adds a shim to support custom manifest 'identifier' #2332
Conversation
This ensures 'adapt_scorm' will be used as a default if the corresponding property is missing.
Declare _advancedSettings as an object if it does not exist.
The hasOwnProperty check always seems like a an overkill when you can use falsies to do the same but with less code. JSON objects don't have an inheritance chain to speak of which is part of the usecase of hasOwnProperty.
The former should suffice as an existence check, as if the property is undefined because it doesn't exist, then it'll fail all the same: if (jsonObject.propertyName) {
// this will return true if the property contains anything that doesn't equate to false
// it doesn't care if the property has been inherited, which it shouldn't have been because we're dealing with JSON
}
if (jsonObject.hasOwnProperty('propertyName')) {
// this will return true if the property has ever been declared regardless of the value assigned, it may still be undefined
// if the property has been inherited it will be ignored here, but one shouldn't have been because we're dealing with JSON
} This works because the default value is only assigned if the jsonObject.propertyName is a falsie, in effect the line is skipped if jsonObject.propertyName has a non-false value: jsonObject.propertyName = jsonObject.propertyName || defaultValue; |
Object references: var a = {
b: {
c: {
value: 1,
value1: 2
}
}
}; If we're going to do a lot of work on object c, then we can store a temporary reference to it in a new variable rather than having to descend through its parents each time to access it. Such that: a.b.c.value = 2;
a.b.c.value1 = 3;
// and
var tempRef = a.b.c;
tempRef.value = 2;
tempRef.value1 = 3;
// are equivalent The same object has been modified in both cases as objects are passed by reference. |
This ensures 'adapt_scorm' will be used as a default if the corresponding property is missing.