我的self creating
是certain conditions
。在if statements
下,某些null
只允许使用某些类型。
目前有效
什么打破了代码
如果代码试图检查它是undefined
还是null
,那么一切都会崩溃。或者,如果它是undefined
或null
,并且我想检查它是否为字符串,则它会崩溃。
我想知道是否有办法通过undefined
或function type(obj) {
obj = Object.prototype.toString.call(obj).split(' ')[1].replace(']', '');
return obj;
}
String.prototype.is = function(what) {
if (/\b(string|str|s)\b/i.test(what)) {
return true;
}
return false;
};
Array.prototype.is = function(what) {
if (/\b(array|arr|a)\b/i.test(what)) {
return true;
}
return false;
};
Object.prototype.is = function(what) {
let results = type(this)
let regex = new RegExp('\\b' + results + '\\b', 'i')
if (regex.test(what)) {
return true;
}
return false;
};
unknown1 = 'hello world'
unknown2 = /a/g
unknown3 = null // Failed to pass through prototype - suppose to log true
unknown4 = undefined // Failed to pass through prototype - suppose to log false
unknown5 = 9
console.log(unknown1.is('string or regexp'))
console.log(unknown2.is('object'))
console.log(unknown3.is('null'))
console.log(unknown4.is('number'))
console.log(unknown5.is('string, number, or object'))
通过?
演示工作直到它准备好检查为空。
{{1}}
答案 0 :(得分:0)
另外......不打破
$Orders_C = array(1,N);