- Code: Select all
/**
* @type {{name:String, status:Number}}
* @properties={typeid:35,uuid:"144D2CC1-0386-472C-88EC-94A564C03C81",variableType:-4}
*/
var CustomType;
/**
* @constructor
* @param {String} name
* @param {Number} status
* @return {scopes.mytypes.CustomType}
* @properties={typeid:24,uuid:"BFF44032-25A3-4664-8415-1020FAB2D4F0"}
*/
function newCustomType(name, status) {
var x = {
name : name,
status : status
};
return x;
}
It seems like a more natural way to accomplish this would to be to allow the referring directly to a constructor function as the type and to be able to use it's @return signature as the type definition. This almost, kind of, works in a few edge cases, but in general falls down for normal usage.
- Code: Select all
/**
* @constructor
* @param {String} name
* @param {Number} status
* @return {{name:String, status:Number}}
* @properties={typeid:24,uuid:"BFF44032-25A3-4664-8415-1020FAB2D4F0"}
*/
function CustomType(name, status) {
var x = {
name : name,
status : status
};
return x;
}
/**
* @type {scopes.mytypes.CustomType}
* @properties={typeid:35,uuid:"E85050E7-2738-4412-80A7-56B22E466539",variableType:-4}
*/
var defaultVal = CustomType("default",0);
/**
* @param {scopes.mytypes.CustomType} x
* @properties={typeid:24,uuid:"DE6836EA-C6AF-4AA0-80D5-66819CBC343B"}
*/
function doSomething(x) {
application.output(x.name); //Warning: The property name is undefined in x
}
/**
* @properties={typeid:24,uuid:"9E6165CE-E4FC-4EC8-B791-89C28FA35B0D"}
*/
function doThings() {
doSomething(defaultVal); //This actually works and shows no warnings
var m = CustomType("name", 10);
doSomething(m); //Warning: The function doSomething(scopes.mytypes.CustomerType) is not applicable for the arguments {{name:String, status:Number}}
}
Given the existence of the @constructor tag it "feels" like Servoy wants us to be able to do things like this.
I know that I want to do things like this.
Can this be real life? Or is it just fantasy...