Child pages
  • New in 7.4

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • SVY-5532SVY-5523SVY-5531SVY-5527 Improved support for JavaScript prototype inside code
    Servoy's Script Editor and Build system now have good support for JavaScript prototyping. This allows creating JavaScript objects using prototyping and having proper code completion and builder markers. Supports both setting an Object as prototype or directly assigning new members to the prototype. Prototype members can be marked as deprecated or protected through JSDoc annotations.

    Expand
    titleSample code
    Code Block
    /**
     * @param {String} name
     *
     * @properties={typeid:24,uuid:"AACFB629-BDC1-4250-BCFA-E564C686153E"}
     */
    function BaseEntity(name) {
    	/**
    	 * Storing name as a protected instance variable
    	 * @protected
    	 */
    	this.name = name
    }
    /**
     * Self executing function (IIFE) to setup the prototype of BaseEntity when the scope in which the functions reside gets instantiated
     * 
     * @private
     * @SuppressWarnings(unused)
     * @properties={typeid:35,uuid:"13635962-8720-4666-9955-6D8BEF94CE38",variableType:-4}
     */
    var initBaseEntity = (function() {
    		//Setting the prototype of BaseEntity to an object with a set of methods
    		BaseEntity.prototype = {
    			publicMethod: function() {},
    			/**
    			 * This is bananas
    			 * @protected
    			 */
    			protectedMethod: function() {},
    			/**
    			 * and this too
    			 * @deprecated
    			 */
    			deprecatedMethod: function() {}
    		}
    		//Extending the previously set prototype object with another method
    		BaseEntity.prototype.getName = function() {
    			return this.name
    		}
    	}())
    
    /**
     * The extends tag signals the build system that public & protected members added through super constructor are known to code completion and the build system<br>
     * <br>
     * The constructor tag takes care of removing the inconsistent return value warning<br>
     * <br>
     *
     * @constructor 
     * @extends {BaseEntity}
     * @param {String} name
     * @param {String} type
     *
     * @properties={typeid:24,uuid:"1D55BCFC-CEE2-4445-95E7-792152E36876"}
     */
    function ExtendedEntity(name, type) {
    	//Fail-save for when the ExtendedEntity gets called without the 'new' keyword
    	if (! (this instanceof ExtendedEntity)) {
    		return new ExtendedEntity(name, type)
    	}
    	//Calling the BaseEntity constructor, so that the logic defined in the constructor is invoked
    	BaseEntity.call(this, name)
    	/**@protected*/
    	this.type = type
    }
    /**
     * Self executing function (IIFE) to setup the prototype of ExtendedEntity when the scope in which the functions reside gets instantiated
     * 
     * @private
     * @SuppressWarnings(unused)
     * @properties={typeid:35,uuid:"8F148031-763B-47B8-A69C-35458EDB6857",variableType:-4}
     */
    var initExtendedEntity = (function() {
    		/* Setting the prototype of ExtendedEntity to an object that has BaseEntity.prototype as prototype
    		 * BaseEntity.prototype is not used directly as prototype for ExtendedEntity, as this would mean that any additions made to
    		 * the prototype of ExtendedEntity would actually be made on the prototype of BaseEntity
    		 */
    		ExtendedEntity.prototype = Object.create(BaseEntity.prototype, {})
    		//Properly set the constructor
    		ExtendedEntity.prototype.constructor = ExtendedEntity
    		ExtendedEntity.prototype.getType = function() {
    			return this.type
    		}
    	}())
    /**
     * @properties={typeid:24,uuid:"586D324D-F1D9-474B-B4EE-E9238E73F80E"}
     */
    function test() {
    	var x = new ExtendedEntity('Servoy', 'company')
    	application.output(x.getName()) //Yields 'Servoy'
    	application.output(x.getType()) //Yields 'company'
    	
    	//These bits of code will result in warnings
    	x.protectedMethod()
    	x.deprecatedMethod()
    	x.name
    	x.type
    }
  • SVY-5615 Improved build system to handle special JavaScript methods like function.call, function.apply, function.bind and Object.create
    For .apply/call/bind, the build system will recognize that the .apply/call/bind method will return the same type as the function on which it is called, for example:

    Expand
    titleSample code
    Code Block
    var x = Object.prototype.toString.call(object) //Build system will know that .call will return a String, as it is called on the .toString() method of Object, which returns a String value
     
    function test() {
        var y = Array.prototype.slice.call(arguments) //Build system will know that y is an Array, as .slice() of Array returns an Array
    }

    For Object.create(object, properties) the build system will know that what Object.create returns has the same type as the value of the object parameter, enhanced with the (optional) properties (See Object.create for more info)

  • SVY-5827 support function types with rest parameters in typedefs

    Expand
    titleSample code
    Code Block
    /**
     * @typedef {{
     * 	name: String,
     *  handler: function(String, Number|*...)
     * }}
     */
    var MyType
  • SVY-5114 Improved support for Union Types in JSDoc
    For example function parameters can now be declared to take an Array containing Strings and/or Numbers.

    Expand
    titleSample code
    Code Block
    /**
     * Method defined to take one argument, which is an Array that can contains both Numbers and Strings
     * @param {Array<String|Number>} arg
     */
    function method(arg) {}
    function demo() {
     //These are fine
     method([1, 'one', 2, 'two', 3, 'three'])
     method([1,2,3])
     method(['one','two','three'])
     
     //This invocation raises a builder marker, as false is neither a Number or a String
     method([1, 'two', false])
    }
  • SVY-5113 Support builder markers when supplying a reference to a function object as value to another functions parameter, but the signature does not match

    Expand
    titleSample code
    Code Block
    /**
     * @param {function(String, Number):Boolean} f
     */
    function method2(f) {
    	
    }
    
    
    function demo2() {
    	/**
    	 * @param {String} name
    	 * @param {Number} age
    	 * @return {Boolean}
    	 */
    	function one(name, age){
    		return true
    	}
    	
    	//No warnings here because the signature of function 'one' matches the requires signative for the 'f' parameter of 'method'
    	method(one)
    	
    	/**
    	 * @param {Number} age
    	 * @param {String} name
    	 * @return {Boolean}
    	 */
    	function two(age, name){
    		return true
    	}
    	
    	//These raise builder markers for obvious reasons
    	method(two)
    	method(function(){})
    }
  • SVY-3555 Enabled the strike-through of deprecated member declarations in the Script Editor

  • SVY-5524 Exposed Error.stack property in scripting
    Allows getting the stacktrace of JavaScript Error objects 
  • SVY-5371 Support returning an instance of itself inside Constructor functions without warnings being generated
    This allows building in a fail-save for Constructor function not being called with the new keyword

    Expand
    titleSample code
    Code Block
    /**
     * @public
     * @constructor
     */
    function MyConstructor(name) {
    	if (!(this instanceof MyConstructor)) { //constructor is not called with the 'new' keyword
    		return new MyConstructor(name)
    	}
    	//rest of the constructor logic
    };
  • SVY-3049 Made the preference to initially fold the Header comment work (Preferences > JavaScript > Editor > Folding)
  • SVY-4876 Fixed the generation of JSDocs through the "Generate Element Comment" option to not insert an @return tag if the function does not return anything 
  • SVY-4226 Improved "move code" option of the Solution Explorer to not insert the scope prefix if inserting into the same scope

...