这是我的 A 类,我希望所有选项都是可选的。它适用于 a、b、c 属性,但不适用于 c.cX 属性。如何正确地使所有属性成为可选?
// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @output_file_name default.js
// ==/ClosureCompiler==
/**
* @typedef {{
* a: (string|undefined),
* b: (number|undefined),
* c: ({
* ca: (string|undefined),
* cb: (number|undefined),
* cc: (Function|undefined)
* }|undefined)
* }}
*/
var Options;
/**
* @param {Options=} options
* @constructor
*/
var A = function(options) {
console.log(this);
};
new A({
a: 'x',
c: {
ca: 'x',
//cb: 1,
cc: function() {}
}
});
Run Code Online (Sandbox Code Playgroud)