如何确定Javascript原型函数是否存在
我知道我可以运行以下命令来确定是否存在正常的Javascript函数:如何确定Javascript原型函数是否存在,javascript,prototypejs,Javascript,Prototypejs,我知道我可以运行以下命令来确定是否存在正常的Javascript函数: if (typeof yourFunctionName == 'function') { yourFunctionName(); } 当我有以下情况时,这是如何工作的: Interface.prototype.yourFunctionName = function() { //ok }; 您只需检查Interface.prototype.yourFunctionName==“function”的类型,如下所示:
if (typeof yourFunctionName == 'function') {
yourFunctionName();
}
当我有以下情况时,这是如何工作的:
Interface.prototype.yourFunctionName = function() { //ok };
您只需检查Interface.prototype.yourFunctionName==“function”的类型,如下所示:
功能接口(){
这个。a=“foo”;
this.b=“bar”;
}
Interface.prototype.yourFunctionName=()=>“baz”;
log(typeof Interface.prototype.yourFunctionName==“function”)代码>typeof Interface.propertype.yourFunctionName==='function'
??属性类型?你是说原型?