问题
Phpstorm keeps telling me I have an undefined variable input.connectto
Html:
<div class="b-showColorinList" data-connectto="123456" data-othervalue="Lorem Ipsum">...
JS:
$(document).on('click', '.b-showColorinList', function() {
cm.showColorInList( $(this) );
});
And:
/**
* Uses ajax to get other color in list view
* @param {object} inputObj
*/
cm.showColorInList = function(inputObj) {
"use strict";
var input = inputObj.data(),
parent = $("#"+input.connectto),
othervalue = input.othervalue;
I know I can ignore a line in jshint, but is there any way to make it correct with jsdoc, example define input
as an object
回答1:
Accordingly to JSDoc docs the proper way should using @typedef
to define actual object structure (especially useful if it will be re-used later in another place) and @type
to declare type of particular variable:
/**
* @typedef {Object} MyInputData
* @property {string} connectto
* @property {string} othervalue
*/
/** @type {MyInputData} */
var input = inputObj.data();
This one (with just @typedef
and variable name as type name) seems to work in PhpStorm as well:
/**
* @typedef {Object} input
* @property {string} connectto
* @property {string} othervalue
*/
var input = inputObj.data();
来源:https://stackoverflow.com/questions/32993268/jshint-phpstorm-unresolved-variable-when-using-jquery-data