0
我试图在我的js应用程序中扩展Object
类。不支持[methodName]选项
这里的方法:
Object.prototype.safeGet = function(props, defaultValue) {
console.log(this, props, defaultValue);
if (typeof props === 'string') {
props = props.split('.');
}
if (this === undefined || this === null) {
return defaultValue;
}
if (props.length === 0) {
return this;
}
return this.safeGet(props.slice(1), defaultValue);
};
当我打开,我得到:
the options [safeGet] is not supported
,然后方法好像是叫(而我做我的代码没有在任何地方),使用以下参数(距console.log
):
SchemaString {
enumValues: [],
regExp: null,
path: 'source',
instance: 'String',
validators:
[ { validator: [Function],
message: 'Path `{PATH}` is required.',
type: 'required' } ],
setters: [],
getters: [],
options:
{ type: [Function: String],
index: true,
required: true,
safeGet: [Function],
runSettersOnQuery: undefined },
_index: true,
isRequired: true,
requiredValidator: [Function],
originalRequiredValue: true } [Function] undefined
使用的NodeJS
$ node --version
v4.8.3
任何想法是怎么回事?更改名称将无济于事。