You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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;
})
}
The text was updated successfully, but these errors were encountered:
Oh, no, I thought about this. I had a problem with that statement, so LET me rewrite it
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' || value === null) {
console.warn(`No ${path} was found for value`)
return original
}
if (typeof value === 'object') {
console.warn(`No ${path} was found for value`)
return original
}
return value
})
}
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
this is my adjustment
The text was updated successfully, but these errors were encountered: