试图通过jsdoc在netbeans中完成JavaScript代码
在我的app.js中,我有以下内容:试图通过jsdoc在netbeans中完成JavaScript代码,javascript,netbeans-7,code-completion,Javascript,Netbeans 7,Code Completion,在我的app.js中,我有以下内容: angular.module('app').controller('userList', ['appSettings' ,function (/*@type {app.appSettings}*/appSettings) { appSettings.<<== it shows a list here but nothing from autocomplete.js NetBeans拒绝为我编写完整的应用程序设置代码,并且似乎不
angular.module('app').controller('userList',
['appSettings'
,function (/*@type {app.appSettings}*/appSettings) {
appSettings.<<== it shows a list here but nothing from autocomplete.js
NetBeans拒绝为我编写完整的应用程序设置代码,并且似乎不知道它是在autocomplete.js中定义的。也许我的js文档弄错了,但我尝试了@var、@type和@param的组合,但没有成功
当我键入app.appSettings.
并从autocomplete.js给我一个列表时,它的代码就完成了,但我想知道如何告诉NetBeans传递给函数的参数是app.appSettings
也许我应该让autocomplete包含构造函数,而不是对象文本,因为@type表示某种类型而不是实例
这是NetBeans 7.3.1很接近答案,让NetBeans使用您输入的类型。然后,为了指示传递给角度模块(或任何函数)的参数属于某种类型,我使用 角度模块:
angular.module('app').controller('userList'
, ['$scope','appRules','appSettings'
,/**
* @param {app.appRules} appRules
* @param {app.appSettings} appSettings
* */
function ($scope,appRules,appSettings,$timeout) {
//<== here both appRules and appSettings give suggestions
// from autocomplete
我在控制台的一个页面上运行了以下代码,该页面包含生成autocomplete.js的应用程序:
var inj;
function allServices(mod, r) {
if (!r) {
r = {};
inj = angular.element(document.querySelector('[data-ng-app]')).injector().get;
}
angular.forEach(angular.module(mod).requires, function(m) {
allServices(m, r)
});
angular.forEach(angular.module(mod)._invokeQueue, function(a) {
try {
r[a[2][0]] = inj(a[2][0]);
} catch (e) {
}
});
return r;
};
var output=[];
function addOutput(names,prop){
if(names.length===1){
output.push('var ');
}
output.push(names.join('.'));
if(typeof prop === 'object'){
output.push('={};\n');
for(thing in prop){
//TODO: no arrays or route paths
if(/[0-9\/\\]/.test(thing)){
continue;
}
names.push(thing);
addOutput(names,prop[thing]);
}
}else{
output.push('=');
output.push(
(typeof prop === 'function')?
prop.toString():
JSON.stringify(prop)
);
output.push(';\n');
}
names.pop();
}
function createOutput(){
allMyServices = allServices('app');
addOutput(['app'],allMyServices);
console.log(output.join(''));
}
createOutput();
/*@typedef {Object} app*/
var app={};
app.appRules={};
app.appRules.userIsInRole=function (user,role){};
app.appRules.general={};
app.appRules.general.isEmpty=function (val){};
app.appRules.general.isEmail=function (val){};
app.appSettings={};
app.appSettings.userFailMessages={};
app.appSettings.userFailMessages.invalidJson
="Invalid request, user sent is not valid json.";
app.appSettings.userFailMessages.noPrivilege
="You do not have the privileges needed to change this user.";
var inj;
function allServices(mod, r) {
if (!r) {
r = {};
inj = angular.element(document.querySelector('[data-ng-app]')).injector().get;
}
angular.forEach(angular.module(mod).requires, function(m) {
allServices(m, r)
});
angular.forEach(angular.module(mod)._invokeQueue, function(a) {
try {
r[a[2][0]] = inj(a[2][0]);
} catch (e) {
}
});
return r;
};
var output=[];
function addOutput(names,prop){
if(names.length===1){
output.push('var ');
}
output.push(names.join('.'));
if(typeof prop === 'object'){
output.push('={};\n');
for(thing in prop){
//TODO: no arrays or route paths
if(/[0-9\/\\]/.test(thing)){
continue;
}
names.push(thing);
addOutput(names,prop[thing]);
}
}else{
output.push('=');
output.push(
(typeof prop === 'function')?
prop.toString():
JSON.stringify(prop)
);
output.push(';\n');
}
names.pop();
}
function createOutput(){
allMyServices = allServices('app');
addOutput(['app'],allMyServices);
console.log(output.join(''));
}
createOutput();