Closed mathieudutour closed 6 years ago
Somehow I completely missed this one.
Do you have any sample script which uses this? I'd like to test it, because I'm curious about the logic of the if statement. Shouldn't it be along the lines of:
if (objCClass && !([propertyName isEqualToString:@"Object"] || [propertyName isEqualToString:@"Function"])) {
?
!a && !b === !(a || b)
so we are both right ;)
lodash
uses Function
in one of its methods:
function isNative(fn) {
// Based on isNative() from Lodash
var funcToString = Function.prototype.toString;
var hasOwnProperty = Object.prototype.hasOwnProperty;
var reIsNative = RegExp('^' + funcToString
// Take an example native function source for comparison
.call(hasOwnProperty
// Strip regex characters so we can use it for regex
).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&'
// Remove hasOwnProperty from the template to make it generic
).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
try {
var source = funcToString.call(fn);
return reIsNative.test(source);
} catch (err) {
return false;
}
}
Yea, you're right now that I stare at the code a bit more. For some reason it tripped something up in my brain from long ago. I'll get this merged.
macOS 10.13.2 has a new class called
Function
so we need to explicitly check for it, same way as we were checking forObject