AngularJS:方法表达式不是函数类型 [英] AngularJS: Method expression is not of Function type

查看:458
本文介绍了AngularJS:方法表达式不是函数类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具有一个定义为的类:

angular.module('trip')
        /** @class MyClass */
        .factory('MyClass', [Factory]);

function Factory() {
   return function(){
         // fields & functions
   }
}

然后在代码中我将实例化一个新对象:

Then in the code I would instantiate a new object:

/**
 * @param {MyClass} MyClass
 */
function(MyClass){
   var myClass = new MyClass(); // HERE MyClass is highlighted in phpStorm
}

当调用new MyClass();时, MyClass 在phpStorm中突出显示,并且出现以下警告:

When calling new MyClass(); the MyClass is highlighted in phpStorm and I get this warning:

方法表达式不是函数类型

Method expression is not of Function type

是什么意思?如何摆脱它?

What does it mean? How to get rid of it?

推荐答案

WebStorm(以及其他工具)将/** @param {MyClass} MyClass */理解为MyClass实例的声明.它说您不能实例化一个实例.我可能只建议将JSDoc更改为/** @param {function():MyClass} MyClass */以停止警告. JSDoc本身并没有提供更好的表达工厂的方式.

WebStorm (along with other tools) understands /** @param {MyClass} MyClass */ as a declaration of an instance of MyClass. It says you can't instantiate an instance. I may only suggest to change JSDoc to /** @param {function():MyClass} MyClass */ to cease the warning. JSDoc itself doesn't offer a better way to express a factory.

此外,请查看 https://youtrack.jetbrains.com/issue/WEB -17325 .

这篇关于AngularJS:方法表达式不是函数类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆