-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Description
Hello, when I was looking at this code, I found that there are repeated judgments and lax writing
I made the following adjustments
I hope you can correct me if I understand wrong, thanks
function replace(input, view) {
// optimization to avoid regex calls (indexOf is strictly faster)
if (input.indexOf(TEMPLATE_OPEN) === -1) return input;
// var result;
// var replaced =
return input.replace(REGEX, function(original, path) {
var value = extractValue(path, view);
// undefined === value , No exception will be thrown. It will throw an exception only if the variable is not declared
// Typeof value == undefined is better
// if (undefined === value || null === value) {
// return original;
// }
// if (typeof value === 'object') {
// result = value;
// return;
//}
// return value;
});
// return (undefined !== result) ? result : replaced;
}
this is my adjustment
function replace(input, view) {
if (input.indexOf(TEMPLATE_OPEN) === -1) return input;
return input.replace(REGEX, function(original, path) {
var value = extractValue(path, view)
if (typeof value == 'undefined' || null === value) return original;
return value;
})
}
Metadata
Metadata
Assignees
Labels
No labels