1016
1017 /* Send DOM event to all elements. Will stop sending event and return
1018 if the previous one is canceled (for cancelable events). */
1019 var sendEvent = function sendEvent (type, cancelable, details) {1020 if (cancelable) {
1021 return !elements.some(function (el) {
1022 var event = new CustomEvent(type, {
151 size--
152 }
153
154 return 0 155 })()
156
157 var getItemExtraData = function (item) {
142 ctx.font = size.toString(10) + 'px sans-serif'
143 if ((ctx.measureText('\uFF37').width === hanWidth) &&
144 (ctx.measureText('m').width) === mWidth) {
145 return (size + 1) 146 }
147
148 hanWidth = ctx.measureText('\uFF37').width
Any code paths that do not have explicit returns will return undefined
.
It is recommended to replace any implicit dead-ends that return undefined
with a return null
statement.
As a convention, undefined
signals that an unexpected value has been produced as the
result of a logical error in the program.
A null
return, on the other hand, signals that the input to a function was incorrect,
or a value was 'not found'.
Having this distinction in code helps you figure out if something was caused because of a logical error, or malformed input to a function call.
function getUser(name) {
if (userExists(name)) {
return userDb.get(name);
}
// whoops! Implicit undefined return
}
function readFile(fileName) {
if (fs.existsSync(fileName)) {
return fs.readFileSync(fileName, 'utf-8');
}
return; // Implicit undefined return.
}
function getUser(name) {
if (userExists(name)) {
return userDb.get(name);
}
// `null` indicates there is no such user.
return null;
}
function readFile(fileName) {
if (fs.existsSync(fileName)) {
return fs.readFileSync(fileName, 'utf-8');
}
// `null` indicates there is no such file.
return null;
}