| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8"> |
| <!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]--> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <meta name="generator" content="Asciidoctor 1.5.5"> |
| <meta name="author" content="2019-08-08 13:15:33 CEST"> |
| <title>N4JS Language Specification</title> |
| <link rel="stylesheet" href="styles/spec.min.css"> |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css"> |
| <!-- ************* docinfo ******************************************************************* --> |
| |
| |
| <!-- ************* Favicon ************--> |
| <link rel="icon" href="images/favicon.ico" /> |
| |
| <!-- ************* Back-to-top JQuery ************* --> |
| <script src="https://code.jquery.com/jquery-1.12.4.js"></script> |
| <script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script> |
| |
| |
| <link href="styles/prism.min.css" rel="stylesheet" /> |
| <script type="text/javascript" async |
| src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML"> |
| </script> |
| |
| <!-- ************* Styles ************* --> |
| <link rel="stylesheet" type="text/css" href="styles/n4jsspec-adoc.css"> |
| |
| |
| <!-- ****************** NavBar ****************** --> |
| <div id="menubar"> |
| <div class="banner"> |
| <a href="https://www.eclipse.org/n4js/#"><img id="logo" src="images/n4js-logo.png" alt="Eclipse N4JS"></a> |
| </div> |
| <ul> |
| <li><a href="index.html">Index</a></li> |
| </ul> |
| </div> |
| <!-- ************* docinfo ******************************************************************* --> |
| <style> |
| .admonitionblock td.icon .icon-todo:before{content:"\f249";color:#f4ee42} |
| </style> |
| </head> |
| <body class="book toc2 toc-left"> |
| <div id="header"> |
| <h1>N4JS Language Specification</h1> |
| <div class="details"> |
| <span id="author" class="author">2019-08-08 13:15:33 CEST</span><br> |
| <span id="revnumber">version 0.9</span> |
| </div> |
| <div id="toc" class="toc2"> |
| <div id="toctitle">Table of Contents</div> |
| <ul class="sectlevel1"> |
| <li><a href="introduction.html#_introduction">1. Introduction</a> |
| <ul class="sectlevel2"> |
| <li><a href="introduction.html#_notation">1.1. Notation</a> |
| <ul class="sectlevel3"> |
| <li><a href="introduction.html#_grammar-notation">1.1.1. Grammar Notation</a></li> |
| <li><a href="introduction.html#_type-judgments-and-rules-and-constraints-notation">1.1.2. Type Judgments and Rules and Constraints Notation</a> |
| <ul class="sectlevel4"> |
| <li><a href="introduction.html#_typing-rules-and-judgments">1.1.2.1. Typing Rules and Judgments</a></li> |
| <li><a href="introduction.html#_types-of-an-element">1.1.2.2. Types of an Element</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="introduction.html#_auxiliary-functions">1.2. Auxiliary Functions</a> |
| <ul class="sectlevel3"> |
| <li><a href="introduction.html#_binding">1.2.1. Binding</a></li> |
| <li><a href="introduction.html#_merging-types">1.2.2. Merging Types</a> |
| <ul class="sectlevel4"> |
| <li><a href="introduction.html#_logic-formulas">1.2.2.1. Logic Formulas</a></li> |
| </ul> |
| </li> |
| <li><a href="introduction.html#_symbols-and-font-convention">1.2.3. Symbols and Font Convention</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="grammar.html#_grammar">2. Grammar</a> |
| <ul class="sectlevel2"> |
| <li><a href="grammar.html#_lexical-conventions">2.1. Lexical Conventions</a> |
| <ul class="sectlevel3"> |
| <li><a href="grammar.html#_identifier-names-and-identifiers">2.1.1. Identifier Names and Identifiers</a></li> |
| <li><a href="grammar.html#_this-keyword">2.1.2. This Keyword</a></li> |
| <li><a href="grammar.html#_regular-expression-literals">2.1.3. Regular Expression Literals</a></li> |
| <li><a href="grammar.html#_automatic-semicolon-insertion">2.1.4. Automatic Semicolon Insertion</a></li> |
| <li><a href="grammar.html#_jsdoc">2.1.5. JSDoc</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="names.html#_names">3. Names</a> |
| <ul class="sectlevel2"> |
| <li><a href="names.html#_access-control">3.1. Access Control</a></li> |
| <li><a href="names.html#_accessibility-of-types-top-level-variables-and-function-declarations">3.2. Accessibility of Types, Top-Level Variables and Function Declarations</a> |
| <ul class="sectlevel3"> |
| <li><a href="names.html#_accessibility-of-members">3.2.1. Accessibility of Members</a></li> |
| <li><a href="names.html#_valid-names">3.2.2. Valid Names</a></li> |
| <li><a href="names.html#_qualified-names">3.2.3. Qualified Names</a></li> |
| <li><a href="names.html#_name-duplicates">3.2.4. Name Duplicates</a> |
| <ul class="sectlevel4"> |
| <li><a href="names.html#_lexical-environment">3.2.4.1. Lexical Environment</a></li> |
| <li><a href="names.html#_duplicates-and-shadowing">3.2.4.2. Duplicates and Shadowing</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="types.html#_types">4. Types</a> |
| <ul class="sectlevel2"> |
| <li><a href="types.html#_overview">4.1. Overview</a></li> |
| <li><a href="types.html#_type-expressions">4.2. Type Expressions</a> |
| <ul class="sectlevel3"> |
| <li><a href="types.html#_syntax">4.2.1. Syntax</a></li> |
| <li><a href="types.html#_properties">4.2.2. Properties</a></li> |
| <li><a href="types.html#_semantics">4.2.3. Semantics</a></li> |
| </ul> |
| </li> |
| <li><a href="types.html#_type-inference">4.3. Type Inference</a></li> |
| <li><a href="types.html#_generic-and-parameterized-types">4.4. Generic and Parameterized Types</a> |
| <ul class="sectlevel3"> |
| <li><a href="types.html#_generic-types">4.4.1. Generic Types</a></li> |
| <li><a href="types.html#_type-variables">4.4.2. Type Variables</a></li> |
| <li><a href="types.html#_parameterized-types">4.4.3. Parameterized Types</a></li> |
| </ul> |
| </li> |
| <li><a href="types.html#_primitive-ecmascript-types">4.5. Primitive ECMAScript Types</a> |
| <ul class="sectlevel3"> |
| <li><a href="types.html#_undefined-type">4.5.1. Undefined Type</a></li> |
| <li><a href="types.html#_null-type">4.5.2. Null Type</a></li> |
| <li><a href="types.html#_primitive-boolean-type">4.5.3. Primitive Boolean Type</a></li> |
| <li><a href="types.html#_primitive-string-type">4.5.4. Primitive String Type</a></li> |
| <li><a href="types.html#_primitive-number-type">4.5.5. Primitive Number Type</a></li> |
| <li><a href="types.html#_primitive-type-int">4.5.6. Primitive Type int</a></li> |
| <li><a href="types.html#_primitive-symbol-type">4.5.7. Primitive Symbol Type</a></li> |
| </ul> |
| </li> |
| <li><a href="types.html#_primitive-n4js-types">4.6. Primitive N4JS Types</a> |
| <ul class="sectlevel3"> |
| <li><a href="types.html#_any-type">4.6.1. Any Type</a> |
| <ul class="sectlevel4"> |
| <li><a href="types.html#any-type-semantics">4.6.1.1. Semantics</a></li> |
| <li><a href="types.html#any-type-type-inference">4.6.1.2. Type Inference</a> |
| <ul class="sectlevel5"> |
| <li><a href="types.html#_default-type-of-variables">4.6.1.2.1. Default Type of Variables</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="types.html#_void-type">4.6.2. Void Type</a> |
| <ul class="sectlevel4"> |
| <li><a href="types.html#void-type-semantics">4.6.2.1. Semantics</a></li> |
| </ul> |
| </li> |
| <li><a href="types.html#_unknown-type">4.6.3. Unknown Type</a></li> |
| <li><a href="types.html#_primitive-pathselector-and-i18nkey">4.6.4. Primitive Pathselector and I18nKey</a> |
| <ul class="sectlevel4"> |
| <li><a href="types.html#pathselector-semantics">4.6.4.1. Semantics</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="types.html#_built-in-ecmascript-object-types">4.7. Built-in ECMAScript Object Types</a> |
| <ul class="sectlevel3"> |
| <li><a href="types.html#ECMAScript-objects-semantics">4.7.1. Semantics</a></li> |
| <li><a href="types.html#_object-type">4.7.2. Object Type</a></li> |
| <li><a href="types.html#_function-object-type">4.7.3. Function-Object-Type</a></li> |
| <li><a href="types.html#_array-object-type">4.7.4. Array Object Type</a></li> |
| <li><a href="types.html#_string-object-type">4.7.5. String Object Type</a></li> |
| <li><a href="types.html#_boolean-object-type">4.7.6. Boolean Object Type</a></li> |
| <li><a href="types.html#_number-object-type">4.7.7. Number Object Type</a></li> |
| <li><a href="types.html#_global-object-type">4.7.8. Global Object Type</a></li> |
| <li><a href="types.html#_symbol">4.7.9. Symbol</a></li> |
| <li><a href="types.html#_promise">4.7.10. Promise</a></li> |
| <li><a href="types.html#_iterator-interface">4.7.11. Iterator Interface</a></li> |
| <li><a href="types.html#_iterable-interface">4.7.12. Iterable Interface</a></li> |
| </ul> |
| </li> |
| <li><a href="types.html#_built-in-n4js-types">4.8. Built-In N4JS Types</a> |
| <ul class="sectlevel3"> |
| <li><a href="types.html#_n4object">4.8.1. N4Object</a> |
| <ul class="sectlevel4"> |
| <li><a href="types.html#N4Object-semantics">4.8.1.1. Semantics</a></li> |
| </ul> |
| </li> |
| <li><a href="types.html#_n4class">4.8.2. N4Class</a></li> |
| <li><a href="types.html#IterableN">4.8.3. IterableN</a></li> |
| </ul> |
| </li> |
| <li><a href="types.html#_type-modifiers">4.9. Type Modifiers</a> |
| <ul class="sectlevel3"> |
| <li><a href="types.html#Type_Modifiers_Dynamic">4.9.1. Dynamic</a></li> |
| <li><a href="types.html#_optional-return-types">4.9.2. Optional Return Types</a></li> |
| </ul> |
| </li> |
| <li><a href="types.html#_union-and-intersection-type-composed-types">4.10. Union and Intersection Type (Composed Types)</a> |
| <ul class="sectlevel3"> |
| <li><a href="types.html#_union-type">4.10.1. Union Type</a> |
| <ul class="sectlevel4"> |
| <li><a href="types.html#union-type-syntax">4.10.1.1. Syntax</a></li> |
| <li><a href="types.html#union-type-semantics">4.10.1.2. Semantics</a></li> |
| <li><a href="types.html#_warnings">4.10.1.3. Warnings</a></li> |
| </ul> |
| </li> |
| <li><a href="types.html#_intersection-type">4.10.2. Intersection Type</a> |
| <ul class="sectlevel4"> |
| <li><a href="types.html#intersection-type-syntax">4.10.2.1. Syntax</a></li> |
| <li><a href="types.html#intersection-type-semantics">4.10.2.2. Semantics</a></li> |
| <li><a href="types.html#_warnings-2">4.10.2.3. Warnings</a></li> |
| </ul> |
| </li> |
| <li><a href="types.html#_composed-types-in-wildcards">4.10.3. Composed Types in Wildcards</a></li> |
| <li><a href="types.html#_property-access-for-composed-types">4.10.4. Property Access for Composed Types</a> |
| <ul class="sectlevel4"> |
| <li><a href="types.html#_properties-of-union-type">4.10.4.1. Properties of Union Type</a> |
| <ul class="sectlevel5"> |
| <li><a href="types.html#_remarks-on-union-type-s-members">4.10.4.1.1. Remarks on union type’s members:</a></li> |
| </ul> |
| </li> |
| <li><a href="types.html#_properties-of-intersection-type">4.10.4.2. Properties of Intersection Type</a> |
| <ul class="sectlevel5"> |
| <li><a href="types.html#_remarks-on-intersection-type-s-methods">4.10.4.2.1. Remarks on intersection type’s methods:</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="types.html#_constructor-and-classifier-type">4.11. Constructor and Classifier Type</a> |
| <ul class="sectlevel3"> |
| <li><a href="types.html#_syntax-3">4.11.1. Syntax</a></li> |
| <li><a href="types.html#_semantics-2">4.11.2. Semantics</a></li> |
| <li><a href="types.html#_constructors-and-prototypes-in-ecmascript-2015">4.11.3. Constructors and Prototypes in ECMAScript 2015</a></li> |
| </ul> |
| </li> |
| <li><a href="types.html#_this-type">4.12. This Type</a> |
| <ul class="sectlevel3"> |
| <li><a href="types.html#this-type-syntax">4.12.1. Syntax</a></li> |
| <li><a href="types.html#this-keyword-semantics">4.12.2. Semantics</a></li> |
| </ul> |
| </li> |
| <li><a href="types.html#_enums">4.13. Enums</a> |
| <ul class="sectlevel3"> |
| <li><a href="types.html#_enums-n4js">4.13.1. Enums (N4JS)</a> |
| <ul class="sectlevel4"> |
| <li><a href="types.html#enums-syntax">4.13.1.1. Syntax</a></li> |
| <li><a href="types.html#enums-semantics">4.13.1.2. Semantics</a></li> |
| </ul> |
| </li> |
| <li><a href="types.html#_string-based-enums">4.13.2. String-Based Enums</a></li> |
| </ul> |
| </li> |
| <li><a href="types.html#_short-hand-syntax">4.14. Short-Hand Syntax</a> |
| <ul class="sectlevel3"> |
| <li><a href="types.html#_array-short-hand-syntax">4.14.1. Array Short-Hand Syntax</a></li> |
| <li><a href="types.html#_iterablen-short-hand-syntax">4.14.2. IterableN Short-Hand Syntax</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="classifiers.html#_classifiers">5. Classifiers</a> |
| <ul class="sectlevel2"> |
| <li><a href="classifiers.html#_n4js-specific-classifiers">5.1. N4JS Specific Classifiers</a> |
| <ul class="sectlevel3"> |
| <li><a href="classifiers.html#_properties-2">5.1.1. Properties</a></li> |
| <li><a href="classifiers.html#_common-semantics-of-classifiers">5.1.2. Common Semantics of Classifiers</a></li> |
| <li><a href="classifiers.html#_classes">5.1.3. Classes</a> |
| <ul class="sectlevel4"> |
| <li><a href="classifiers.html#_definition-of-classes">5.1.3.1. Definition of Classes</a> |
| <ul class="sectlevel5"> |
| <li><a href="classifiers.html#class-syntax">5.1.3.1.1. Syntax</a></li> |
| <li><a href="classifiers.html#class-properties">5.1.3.1.2. Properties</a></li> |
| <li><a href="classifiers.html#class-type-inference">5.1.3.1.3. Type Inference</a></li> |
| </ul> |
| </li> |
| <li><a href="classifiers.html#class-semantics">5.1.3.2. Semantics</a></li> |
| <li><a href="classifiers.html#_final-modifier">5.1.3.3. Final Modifier</a></li> |
| <li><a href="classifiers.html#_abstract-classes">5.1.3.4. Abstract Classes</a></li> |
| <li><a href="classifiers.html#_non-instantiable-classes">5.1.3.5. Non-Instantiable Classes</a></li> |
| <li><a href="classifiers.html#_superclass">5.1.3.6. Superclass</a></li> |
| </ul> |
| </li> |
| <li><a href="classifiers.html#_interfaces">5.1.4. Interfaces</a> |
| <ul class="sectlevel4"> |
| <li><a href="classifiers.html#_definition-of-interfaces">5.1.4.1. Definition of Interfaces</a> |
| <ul class="sectlevel5"> |
| <li><a href="classifiers.html#interfaces-syntax">5.1.4.1.1. Syntax</a></li> |
| <li><a href="classifiers.html#interfaces-properties">5.1.4.1.2. Properties</a></li> |
| <li><a href="classifiers.html#interfaces-type-inference">5.1.4.1.3. Type Inference</a></li> |
| <li><a href="classifiers.html#interfaces-semantics">5.1.4.1.4. Semantics</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="classifiers.html#_generic-classifiers">5.1.5. Generic Classifiers</a></li> |
| <li><a href="classifiers.html#sec:definition-site-variance">5.1.6. Definition-Site Variance</a></li> |
| </ul> |
| </li> |
| <li><a href="classifiers.html#_members">5.2. Members</a> |
| <ul class="sectlevel3"> |
| <li><a href="classifiers.html#_syntax-4">5.2.1. Syntax</a> |
| <ul class="sectlevel4"> |
| <li><a href="classifiers.html#_properties-3">5.2.1.1. Properties</a></li> |
| </ul> |
| </li> |
| <li><a href="classifiers.html#_semantics-3">5.2.2. Semantics</a></li> |
| <li><a href="classifiers.html#_methods">5.2.3. Methods</a> |
| <ul class="sectlevel4"> |
| <li><a href="classifiers.html#_syntax-5">5.2.3.1. Syntax</a></li> |
| <li><a href="classifiers.html#_properties-4">5.2.3.2. Properties</a></li> |
| <li><a href="classifiers.html#_semantics-4">5.2.3.3. Semantics</a></li> |
| <li><a href="classifiers.html#_final-methods">5.2.3.4. Final Methods</a></li> |
| <li><a href="classifiers.html#_abstract-methods">5.2.3.5. Abstract Methods</a></li> |
| <li><a href="classifiers.html#_generic-methods">5.2.3.6. Generic Methods</a></li> |
| </ul> |
| </li> |
| <li><a href="classifiers.html#_default-methods-in-interfaces">5.2.4. Default Methods in Interfaces</a> |
| <ul class="sectlevel4"> |
| <li><a href="classifiers.html#_asynchronous-methods">5.2.4.1. Asynchronous Methods</a></li> |
| </ul> |
| </li> |
| <li><a href="classifiers.html#_constructors">5.2.5. Constructors</a> |
| <ul class="sectlevel4"> |
| <li><a href="classifiers.html#_structural-this-type-in-constructor">5.2.5.1. Structural This Type in Constructor</a></li> |
| <li><a href="classifiers.html#spec-constructor">5.2.5.2. @Spec Constructor</a></li> |
| <li><a href="classifiers.html#_callable-constructors">5.2.5.3. Callable Constructors</a></li> |
| <li><a href="classifiers.html#_covariant-constructors">5.2.5.4. Covariant Constructors</a></li> |
| </ul> |
| </li> |
| <li><a href="classifiers.html#_data-fields">5.2.6. Data Fields</a> |
| <ul class="sectlevel4"> |
| <li><a href="classifiers.html#data-fields-syntax">5.2.6.1. Syntax</a></li> |
| <li><a href="classifiers.html#data-fields-properties">5.2.6.2. Properties</a> |
| <ul class="sectlevel5"> |
| <li><a href="classifiers.html#data-fields-semantics">5.2.6.2.1. Semantics</a></li> |
| <li><a href="classifiers.html#data-fields-type-inference">5.2.6.2.2. Type Inference</a></li> |
| </ul> |
| </li> |
| <li><a href="classifiers.html#_assignment-modifiers">5.2.6.3. Assignment Modifiers</a></li> |
| <li><a href="classifiers.html#_field-accessors-getter-setter">5.2.6.4. Field Accessors (Getter/Setter)</a> |
| <ul class="sectlevel5"> |
| <li><a href="classifiers.html#field-acessors-syntax">5.2.6.4.1. Syntax</a></li> |
| <li><a href="classifiers.html#field-acessors-properties">5.2.6.4.2. Properties</a></li> |
| <li><a href="classifiers.html#field-accessors-semantics">5.2.6.4.3. Semantics</a></li> |
| </ul> |
| </li> |
| <li><a href="classifiers.html#optional-fields">5.2.6.5. Optional Fields</a> |
| <ul class="sectlevel5"> |
| <li><a href="classifiers.html#_syntax-6">5.2.6.5.1. Syntax</a></li> |
| <li><a href="classifiers.html#_semantics-5">5.2.6.5.2. Semantics</a></li> |
| <li><a href="classifiers.html#_background">5.2.6.5.3. Background</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="classifiers.html#_static-members">5.2.7. Static Members</a> |
| <ul class="sectlevel4"> |
| <li><a href="classifiers.html#_access-from-and-to-static-members">5.2.7.1. Access From and To Static Members</a></li> |
| <li><a href="classifiers.html#_generic-static-methods">5.2.7.2. Generic static methods</a></li> |
| <li><a href="classifiers.html#_static-members-of-interfaces">5.2.7.3. Static Members of Interfaces</a></li> |
| </ul> |
| </li> |
| <li><a href="classifiers.html#_redefinition-of-members">5.2.8. Redefinition of Members</a> |
| <ul class="sectlevel4"> |
| <li><a href="classifiers.html#_overriding-of-members">5.2.8.1. Overriding of Members</a></li> |
| <li><a href="classifiers.html#_implementation-of-members">5.2.8.2. Implementation of Members</a> |
| <ul class="sectlevel5"> |
| <li><a href="classifiers.html#_member-consumption">5.2.8.2.1. Member Consumption</a></li> |
| <li><a href="classifiers.html#_member-implementation">5.2.8.2.2. Member Implementation</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="classifiers.html#_structural-typing">5.3. Structural Typing</a> |
| <ul class="sectlevel3"> |
| <li><a href="classifiers.html#_syntax-7">5.3.1. Syntax</a></li> |
| <li><a href="classifiers.html#_definition-site-structural-typing">5.3.2. Definition Site Structural Typing</a></li> |
| <li><a href="classifiers.html#_use-site-structural-typing">5.3.3. Use-Site Structural Typing</a></li> |
| <li><a href="classifiers.html#structural-readWriteInit-field-typing">5.3.4. Structural Read-only, Write-only and Initializer Field Typing</a></li> |
| <li><a href="classifiers.html#_public-setter-annotated-with-code-providesinitializer-code">5.3.5. Public Setter Annotated With <code>ProvidesInitializer</code></a></li> |
| <li><a href="classifiers.html#_structural-types-with-optional-fields">5.3.6. Structural Types With Optional Fields</a></li> |
| <li><a href="classifiers.html#_structural-types-with-access-modifier">5.3.7. Structural Types With Access Modifier</a></li> |
| <li><a href="classifiers.html#_structural-types-with-additional-members">5.3.8. Structural Types With Additional Members</a> |
| <ul class="sectlevel4"> |
| <li><a href="classifiers.html#_syntax-8">5.3.8.1. Syntax</a> |
| <ul class="sectlevel5"> |
| <li><a href="classifiers.html#_semantics-6">5.3.8.1.1. Semantics</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="functions.html#_functions">6. Functions</a> |
| <ul class="sectlevel2"> |
| <li><a href="functions.html#_function-type">6.1. Function Type</a> |
| <ul class="sectlevel3"> |
| <li><a href="functions.html#_properties-5">6.1.1. Properties</a></li> |
| <li><a href="functions.html#function-type-inference">6.1.2. Type Inference</a></li> |
| <li><a href="functions.html#_autoboxing-of-function-type">6.1.3. Autoboxing of Function Type</a></li> |
| <li><a href="functions.html#_arguments-object">6.1.4. Arguments Object</a></li> |
| </ul> |
| </li> |
| <li><a href="functions.html#_ecmascript-5-function-definition">6.2. ECMAScript 5 Function Definition</a> |
| <ul class="sectlevel3"> |
| <li><a href="functions.html#_function-declaration">6.2.1. Function Declaration</a> |
| <ul class="sectlevel4"> |
| <li><a href="functions.html#_syntax-9">6.2.1.1. Syntax</a></li> |
| <li><a href="functions.html#_semantics-8">6.2.1.2. Semantics</a></li> |
| </ul> |
| </li> |
| <li><a href="functions.html#_function-expression">6.2.2. Function Expression</a> |
| <ul class="sectlevel4"> |
| <li><a href="functions.html#function-expression-syntax">6.2.2.1. Syntax</a></li> |
| <li><a href="functions.html#_semantics-and-type-inference">6.2.2.2. Semantics and Type Inference</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="functions.html#_ecmascript-2015-function-definition">6.3. ECMAScript 2015 Function Definition</a> |
| <ul class="sectlevel3"> |
| <li><a href="functions.html#_formal-parameters">6.3.1. Formal Parameters</a> |
| <ul class="sectlevel4"> |
| <li><a href="functions.html#Type_Modifiers_Optional">6.3.1.1. Optional Parameters</a></li> |
| <li><a href="functions.html#Type_Modifiers_Default">6.3.1.2. Default Parameters</a></li> |
| <li><a href="functions.html#Type_Modifiers_Variadic">6.3.1.3. Variadic</a></li> |
| </ul> |
| </li> |
| <li><a href="functions.html#_generator-functions">6.3.2. Generator Functions</a> |
| <ul class="sectlevel4"> |
| <li><a href="functions.html#generator-functions-syntax">6.3.2.1. Syntax</a></li> |
| <li><a href="functions.html#generator-functions-semantics">6.3.2.2. Semantics</a></li> |
| <li><a href="functions.html#_generator-arrow-functions">6.3.2.3. Generator Arrow Functions</a></li> |
| </ul> |
| </li> |
| <li><a href="functions.html#_arrow-function-expression">6.3.3. Arrow Function Expression</a> |
| <ul class="sectlevel4"> |
| <li><a href="functions.html#arrow-function-expression-syntax">6.3.3.1. Syntax</a></li> |
| <li><a href="functions.html#arrow-function-expression-semantics-and-type-inference">6.3.3.2. Semantics and Type Inference</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="functions.html#_ecmascript-proposals-function-definition">6.4. ECMAScript Proposals Function Definition</a> |
| <ul class="sectlevel3"> |
| <li><a href="functions.html#_asynchronous-functions">6.4.1. Asynchronous Functions</a> |
| <ul class="sectlevel4"> |
| <li><a href="functions.html#asynchronous-functions-syntax">6.4.1.1. Syntax</a></li> |
| <li><a href="functions.html#asynchronous-functions-semantics">6.4.1.2. Semantics</a></li> |
| <li><a href="functions.html#_asynchronous-arrow-functions">6.4.1.3. Asynchronous Arrow Functions</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="functions.html#_n4js-extended-function-definition">6.5. N4JS Extended Function Definition</a> |
| <ul class="sectlevel3"> |
| <li><a href="functions.html#_generic-functions">6.5.1. Generic Functions</a></li> |
| <li><a href="functions.html#_promisifiable-functions">6.5.2. Promisifiable Functions</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="#_conversions-and-reflection">7. Conversions and Reflection</a> |
| <ul class="sectlevel2"> |
| <li><a href="#_autoboxing-and-coercing">7.1. Autoboxing and Coercing</a> |
| <ul class="sectlevel3"> |
| <li><a href="#_coercing">7.1.1. Coercing</a></li> |
| <li><a href="#_autoboxing-of-primitives">7.1.2. Autoboxing of Primitives</a></li> |
| <li><a href="#_autoboxing-of-function-expressions-and-declarations">7.1.3. Autoboxing of Function Expressions and Declarations</a></li> |
| </ul> |
| </li> |
| <li><a href="#_auto-conversion-of-objects">7.2. Auto-Conversion of Objects</a> |
| <ul class="sectlevel3"> |
| <li><a href="#_auto-conversion-of-class-instances">7.2.1. Auto-Conversion of Class Instances</a> |
| <ul class="sectlevel4"> |
| <li><a href="#_auto-conversion-of-interface-instances">7.2.1.1. Auto-Conversion of Interface Instances</a></li> |
| </ul> |
| </li> |
| <li><a href="#_auto-conversion-of-enum-literals">7.2.2. Auto-Conversion of Enum Literals</a></li> |
| </ul> |
| </li> |
| <li><a href="#_type-cast-and-type-check">7.3. Type Cast and Type Check</a> |
| <ul class="sectlevel3"> |
| <li><a href="#_type-cast">7.3.1. Type Cast</a></li> |
| <li><a href="#_type-check">7.3.2. Type Check</a></li> |
| </ul> |
| </li> |
| <li><a href="#_reflection-meta-information">7.4. Reflection meta-information</a> |
| <ul class="sectlevel3"> |
| <li><a href="#_reflection-for-classes">7.4.1. Reflection for Classes</a></li> |
| <li><a href="#_reflection-for-interfaces">7.4.2. Reflection for Interfaces</a></li> |
| <li><a href="#_reflection-for-enumerations">7.4.3. Reflection for Enumerations</a></li> |
| </ul> |
| </li> |
| <li><a href="#_conversion-of-primitive-types">7.5. Conversion of primitive types</a></li> |
| </ul> |
| </li> |
| <li><a href="expressions.html#_expressions">8. Expressions</a> |
| <ul class="sectlevel2"> |
| <li><a href="expressions.html#_ecmascript-5-expressions">8.1. ECMAScript 5 Expressions</a> |
| <ul class="sectlevel3"> |
| <li><a href="expressions.html#_the-this-literal">8.1.1. The this Literal</a></li> |
| <li><a href="expressions.html#_identifier">8.1.2. Identifier</a></li> |
| <li><a href="expressions.html#_literals">8.1.3. Literals</a> |
| <ul class="sectlevel4"> |
| <li><a href="expressions.html#_integer-literals">8.1.3.1. Integer Literals</a></li> |
| </ul> |
| </li> |
| <li><a href="expressions.html#_array-literal">8.1.4. Array Literal</a></li> |
| <li><a href="expressions.html#_object-literal">8.1.5. Object Literal</a> |
| <ul class="sectlevel4"> |
| <li><a href="expressions.html#_properties-6">8.1.5.1. Properties</a></li> |
| <li><a href="expressions.html#_scoping-and-linking">8.1.5.2. Scoping and linking</a></li> |
| </ul> |
| </li> |
| <li><a href="expressions.html#_parenthesized-expression-and-grouping-operator">8.1.6. Parenthesized Expression and Grouping Operator</a></li> |
| <li><a href="expressions.html#_property-accessors">8.1.7. Property Accessors</a> |
| <ul class="sectlevel4"> |
| <li><a href="expressions.html#properties-1">8.1.7.1. Properties</a></li> |
| </ul> |
| </li> |
| <li><a href="expressions.html#_new-expression">8.1.8. New Expression</a></li> |
| <li><a href="expressions.html#_function-expression-2">8.1.9. Function Expression</a></li> |
| <li><a href="expressions.html#_function-calls">8.1.10. Function Calls</a></li> |
| <li><a href="expressions.html#_postfix-expression">8.1.11. Postfix Expression</a></li> |
| <li><a href="expressions.html#_unary-expression">8.1.12. Unary Expression</a></li> |
| <li><a href="expressions.html#_multiplicative-expression">8.1.13. Multiplicative Expression</a></li> |
| <li><a href="expressions.html#_additive-expression">8.1.14. Additive Expression</a> |
| <ul class="sectlevel4"> |
| <li><a href="expressions.html#type-inference-10">8.1.14.1. Type Inference</a></li> |
| </ul> |
| </li> |
| <li><a href="expressions.html#_bitwise-shift-expression">8.1.15. Bitwise Shift Expression</a></li> |
| <li><a href="expressions.html#_relational-expression">8.1.16. Relational Expression</a></li> |
| <li><a href="expressions.html#_equality-expression">8.1.17. Equality Expression</a></li> |
| <li><a href="expressions.html#_binary-bitwise-expression">8.1.18. Binary Bitwise Expression</a></li> |
| <li><a href="expressions.html#_binary-logical-expression">8.1.19. Binary Logical Expression</a></li> |
| <li><a href="expressions.html#_conditional-expression">8.1.20. Conditional Expression</a></li> |
| <li><a href="expressions.html#_assignment-expression">8.1.21. Assignment Expression</a></li> |
| <li><a href="expressions.html#_comma-expression">8.1.22. Comma Expression</a></li> |
| </ul> |
| </li> |
| <li><a href="expressions.html#_ecmascript-6-expressions">8.2. ECMAScript 6 Expressions</a> |
| <ul class="sectlevel3"> |
| <li><a href="expressions.html#_the-super-keyword">8.2.1. The super Keyword</a></li> |
| </ul> |
| </li> |
| <li><a href="expressions.html#_ecmascript-7-expressions">8.3. ECMAScript 7 Expressions</a> |
| <ul class="sectlevel3"> |
| <li><a href="expressions.html#_await-expression">8.3.1. Await Expression</a></li> |
| </ul> |
| </li> |
| <li><a href="expressions.html#_n4js-specific-expressions">8.4. N4JS Specific Expressions</a> |
| <ul class="sectlevel3"> |
| <li><a href="expressions.html#_class-expression">8.4.1. Class Expression</a></li> |
| <li><a href="expressions.html#_cast-as-expression">8.4.2. Cast (As) Expression</a> |
| <ul class="sectlevel4"> |
| <li><a href="expressions.html#cast-as-expression-semantics-type-inference">8.4.2.1. Semantics and Type Inference</a></li> |
| </ul> |
| </li> |
| <li><a href="expressions.html#Import_Calls">8.4.3. Import Calls</a></li> |
| </ul> |
| </li> |
| <li><a href="expressions.html#compile-time-expressions">8.5. Compile-Time Expressions</a></li> |
| </ul> |
| </li> |
| <li><a href="statements.html#_statements">9. Statements</a> |
| <ul class="sectlevel2"> |
| <li><a href="statements.html#_ecmascript-5-statements">9.1. ECMAScript 5 Statements</a> |
| <ul class="sectlevel3"> |
| <li><a href="statements.html#_function-or-field-accessor-bodies">9.1.1. Function or Field Accessor Bodies</a></li> |
| <li><a href="statements.html#_variable-statement">9.1.2. Variable Statement</a></li> |
| <li><a href="statements.html#_if-statement">9.1.3. If Statement</a></li> |
| <li><a href="statements.html#_iteration-statements">9.1.4. Iteration Statements</a></li> |
| <li><a href="statements.html#_return-statement">9.1.5. Return Statement</a></li> |
| <li><a href="statements.html#_with-statement">9.1.6. With Statement</a></li> |
| <li><a href="statements.html#_switch-statement">9.1.7. Switch Statement</a></li> |
| <li><a href="statements.html#_throw-try-and-catch-statements">9.1.8. Throw, Try, and Catch Statements</a></li> |
| <li><a href="statements.html#_debugger-statement">9.1.9. Debugger Statement</a></li> |
| </ul> |
| </li> |
| <li><a href="statements.html#_ecmascript-6-statements">9.2. ECMAScript 6 Statements</a> |
| <ul class="sectlevel3"> |
| <li><a href="statements.html#_let">9.2.1. Let</a></li> |
| <li><a href="statements.html#_const">9.2.2. Const</a></li> |
| <li><a href="statements.html#_for-of-statement">9.2.3. <code>for …​ of</code> statement</a></li> |
| <li><a href="statements.html#_import-statement">9.2.4. Import Statement</a> |
| <ul class="sectlevel4"> |
| <li><a href="statements.html#Dynamic_Imports">9.2.4.1. Dynamic Imports</a></li> |
| <li><a href="statements.html#_immutabilaty-of-imports">9.2.4.2. Immutabilaty of Imports</a></li> |
| </ul> |
| </li> |
| <li><a href="statements.html#_export-statement">9.2.5. Export Statement</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="annotations.html#_annotations">10. Annotations</a> |
| <ul class="sectlevel2"> |
| <li><a href="annotations.html#_introduction-2">10.1. Introduction</a> |
| <ul class="sectlevel3"> |
| <li><a href="annotations.html#_syntax-13">10.1.1. Syntax</a></li> |
| <li><a href="annotations.html#_properties-7">10.1.2. Properties</a></li> |
| <li><a href="annotations.html#_element-specific-annotations">10.1.3. Element-Specific Annotations</a></li> |
| <li><a href="annotations.html#_general-annotations">10.1.4. General Annotations</a> |
| <ul class="sectlevel4"> |
| <li><a href="annotations.html#_idebug">10.1.4.1. IDEBUG</a></li> |
| </ul> |
| </li> |
| <li><a href="annotations.html#idebug-syntax">10.1.5. Syntax</a> |
| <ul class="sectlevel4"> |
| <li><a href="annotations.html#_semantics-11">10.1.5.1. Semantics</a></li> |
| <li><a href="annotations.html#_suppress-warnings">10.1.5.2. Suppress Warnings</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="annotations.html#_declaration-of-annotations">10.2. Declaration of Annotations</a></li> |
| </ul> |
| </li> |
| <li><a href="extended_fetaures.html#_extended-fetaures">11. Extended Fetaures</a> |
| <ul class="sectlevel2"> |
| <li><a href="extended_fetaures.html#_array-and-object-destructuring">11.1. Array and Object Destructuring</a> |
| <ul class="sectlevel3"> |
| <li><a href="extended_fetaures.html#_syntax-14">11.1.1. Syntax</a></li> |
| <li><a href="extended_fetaures.html#_semantics-12">11.1.2. Semantics</a></li> |
| </ul> |
| </li> |
| <li><a href="extended_fetaures.html#_dependency-injection">11.2. Dependency Injection</a> |
| <ul class="sectlevel3"> |
| <li><a href="extended_fetaures.html#_di-components-and-injectors">11.2.1. DI Components and Injectors</a> |
| <ul class="sectlevel4"> |
| <li><a href="extended_fetaures.html#_dicomponent-relations">11.2.1.1. DIComponent Relations</a></li> |
| </ul> |
| </li> |
| <li><a href="extended_fetaures.html#_binders-and-bindings">11.2.2. Binders and Bindings</a></li> |
| <li><a href="extended_fetaures.html#_injection-points">11.2.3. Injection Points</a> |
| <ul class="sectlevel4"> |
| <li><a href="extended_fetaures.html#_field-injection">11.2.3.1. Field Injection</a></li> |
| <li><a href="extended_fetaures.html#_constructor-injection">11.2.3.2. Constructor Injection</a></li> |
| <li><a href="extended_fetaures.html#_method-injection">11.2.3.3. Method Injection</a> |
| <ul class="sectlevel5"> |
| <li><a href="extended_fetaures.html#_provider">11.2.3.3.1. Provider</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="extended_fetaures.html#_n4js-di-life-cycle-and-scopes">11.2.4. N4JS DI Life Cycle and Scopes</a> |
| <ul class="sectlevel4"> |
| <li><a href="extended_fetaures.html#_injection-cylces">11.2.4.1. Injection Cylces</a></li> |
| <li><a href="extended_fetaures.html#_default-scope">11.2.4.2. Default Scope</a></li> |
| <li><a href="extended_fetaures.html#_singleton-scope">11.2.4.3. Singleton Scope</a></li> |
| <li><a href="extended_fetaures.html#_per-injection-chain-singleton">11.2.4.4. Per Injection Chain Singleton</a></li> |
| </ul> |
| </li> |
| <li><a href="extended_fetaures.html#_validation-of-callsites-targeting-n4injector-methods">11.2.5. Validation of callsites targeting N4Injector methods</a></li> |
| <li><a href="extended_fetaures.html#_n4js-di-annotations">11.2.6. N4JS DI Annotations</a> |
| <ul class="sectlevel4"> |
| <li><a href="extended_fetaures.html#_n4js-di-generateinjector">11.2.6.1. N4JS DI @GenerateInjector</a></li> |
| <li><a href="extended_fetaures.html#_n4js-di-withparentinjector">11.2.6.2. N4JS DI @WithParentInjector</a></li> |
| <li><a href="extended_fetaures.html#_n4js-di-usebinder">11.2.6.3. N4JS DI @UseBinder</a></li> |
| <li><a href="extended_fetaures.html#_n4js-di-binder">11.2.6.4. N4JS DI @Binder</a></li> |
| <li><a href="extended_fetaures.html#_n4js-di-bind">11.2.6.5. N4JS DI @Bind</a></li> |
| <li><a href="extended_fetaures.html#_n4js-di-provides">11.2.6.6. N4JS DI @Provides</a></li> |
| <li><a href="extended_fetaures.html#_n4js-di-inject">11.2.6.7. N4JS DI @Inject</a></li> |
| <li><a href="extended_fetaures.html#_n4js-di-singleton">11.2.6.8. N4JS DI @Singleton</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="extended_fetaures.html#_test-support">11.3. Test Support</a></li> |
| <li><a href="extended_fetaures.html#_polyfill-definitions">11.4. Polyfill Definitions</a> |
| <ul class="sectlevel3"> |
| <li><a href="extended_fetaures.html#_runtime-polyfill-definitions">11.4.1. Runtime Polyfill Definitions</a></li> |
| <li><a href="extended_fetaures.html#_static-polyfill-definitions">11.4.2. Static Polyfill Definitions</a></li> |
| <li><a href="extended_fetaures.html#_transpiling-static-polyfilled-classes">11.4.3. Transpiling static polyfilled classes</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="components.html#_components">12. Components</a> |
| <ul class="sectlevel2"> |
| <li><a href="components.html#_overview-2">12.1. Overview</a></li> |
| <li><a href="components.html#Component_Types">12.2. Component Types</a> |
| <ul class="sectlevel3"> |
| <li><a href="components.html#_libraries">12.2.1. Libraries</a></li> |
| <li><a href="components.html#_runtime-environment-and-runtime-libraries">12.2.2. Runtime Environment and Runtime Libraries</a></li> |
| <li><a href="components.html#_tests">12.2.3. Tests</a></li> |
| <li><a href="components.html#_type-definitions">12.2.4. Type Definitions</a></li> |
| </ul> |
| </li> |
| <li><a href="components.html#package-json">12.3. Package.json File</a> |
| <ul class="sectlevel3"> |
| <li><a href="components.html#_basic-properties">12.3.1. Basic Properties</a></li> |
| <li><a href="components.html#_n4js-properties">12.3.2. N4JS Properties</a></li> |
| <li><a href="components.html#_constraints">12.3.3. Constraints</a></li> |
| </ul> |
| </li> |
| <li><a href="components.html#_support-for-npm-scopes">12.4. Support for NPM Scopes</a></li> |
| <li><a href="components.html#sec:N4JS-Type-Definitions">12.5. N4JS Type Definitions</a> |
| <ul class="sectlevel3"> |
| <li><a href="components.html#_specify-type-definition">12.5.1. Specify Type Definition</a></li> |
| <li><a href="components.html#_name-conventions">12.5.2. Name Conventions</a></li> |
| <li><a href="components.html#_version-conventions">12.5.3. Version Conventions</a> |
| <ul class="sectlevel4"> |
| <li><a href="components.html#_define-a-new-type-definition-package">12.5.3.1. Define a New Type Definition Package</a></li> |
| <li><a href="components.html#_using-a-type-definition-package">12.5.3.2. Using a Type Definition Package</a></li> |
| <li><a href="components.html#_rational">12.5.3.3. Rational</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="components.html#_modules">12.6. Modules</a></li> |
| <li><a href="components.html#_api-and-implementation-component">12.7. API and Implementation Component</a> |
| <ul class="sectlevel3"> |
| <li><a href="components.html#_execution-of-api-and-implementation-components">12.7.1. Execution of API and Implementation Components</a></li> |
| <li><a href="components.html#_api-and-implementation-with-di">12.7.2. API and Implementation With DI</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="plainjs.html#_plainjs">13. PlainJS</a> |
| <ul class="sectlevel2"> |
| <li><a href="plainjs.html#_type-inference-and-validation-for-plain-js">13.1. Type Inference and Validation for Plain JS</a></li> |
| <li><a href="plainjs.html#_external-declarations">13.2. External Declarations</a> |
| <ul class="sectlevel3"> |
| <li><a href="plainjs.html#_declaring-externals">13.2.1. Declaring externals</a></li> |
| <li><a href="plainjs.html#_instantiating-external-classes">13.2.2. Instantiating external classes</a></li> |
| <li><a href="plainjs.html#_implementation-of-external-declarations">13.2.3. Implementation of External Declarations</a></li> |
| <li><a href="plainjs.html#_example">13.2.4. Example</a></li> |
| </ul> |
| </li> |
| <li><a href="plainjs.html#_global-definitions">13.3. Global Definitions</a></li> |
| <li><a href="plainjs.html#_runtime-definitions">13.4. Runtime Definitions</a></li> |
| <li><a href="plainjs.html#_applying-polyfills">13.5. Applying Polyfills</a></li> |
| </ul> |
| </li> |
| <li><a href="jsdoc.html#_jsdoc-2">14. JSDoc</a> |
| <ul class="sectlevel2"> |
| <li><a href="jsdoc.html#_general-n4jsdoc-features">14.1. General N4JSDoc Features</a> |
| <ul class="sectlevel3"> |
| <li><a href="jsdoc.html#_provided-inline-tags">14.1.1. Provided Inline Tags</a> |
| <ul class="sectlevel4"> |
| <li><a href="jsdoc.html#jsdoc_tag__code">14.1.1.1. @code</a></li> |
| <li><a href="jsdoc.html#jsdoc_tag__link">14.1.1.2. @link</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="jsdoc.html#_n4jsdoc-for-user-projects">14.2. N4JSdoc for User Projects</a> |
| <ul class="sectlevel3"> |
| <li><a href="jsdoc.html#_standard-tags">14.2.1. Standard Tags</a> |
| <ul class="sectlevel4"> |
| <li><a href="jsdoc.html#_-author">14.2.1.1. @author</a></li> |
| <li><a href="jsdoc.html#jsdoc_tag_param">14.2.1.2. @param</a></li> |
| <li><a href="jsdoc.html#jsdoc_tag_return">14.2.1.3. @return</a></li> |
| </ul> |
| </li> |
| <li><a href="jsdoc.html#_test-related-tags">14.2.2. Test Related Tags</a> |
| <ul class="sectlevel4"> |
| <li><a href="jsdoc.html#jsdoc_tag__testee">14.2.2.1. @testee</a></li> |
| <li><a href="jsdoc.html#jsdoc_tag__testeeFromType">14.2.2.2. @testeeFromType</a></li> |
| <li><a href="jsdoc.html#_testeeType_and__testeeMember">14.2.2.3. @testeeType and @testeeMember</a></li> |
| <li><a href="jsdoc.html#jsdoc_tag_reqid_in_Tests">14.2.2.4. @reqid in Tests</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="jsdoc.html#_n4jsdoc-for-api-and-implementation-projects">14.3. N4JSDoc for API and Implementation Projects</a> |
| <ul class="sectlevel3"> |
| <li><a href="jsdoc.html#jsdoc_tag__apiNote">14.3.1. @apiNote</a></li> |
| <li><a href="jsdoc.html#API_Project_Tags">14.3.2. API Project Tags</a> |
| <ul class="sectlevel4"> |
| <li><a href="jsdoc.html#jsdoc_tag_apiState">14.3.2.1. @apiState</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="jsx.html#_jsx">15. JSX</a> |
| <ul class="sectlevel2"> |
| <li><a href="jsx.html#_jsx-support">15.1. JSX Support</a></li> |
| <li><a href="jsx.html#_jsx-backend">15.2. JSX Backend</a></li> |
| </ul> |
| </li> |
| <li><a href="grammars.html#_grammars">16. Grammars</a> |
| <ul class="sectlevel2"> |
| <li><a href="grammars.html#_type-expressions-grammar">16.1. Type Expressions Grammar</a></li> |
| <li><a href="grammars.html#_n4js-language-grammar">16.2. N4JS Language Grammar</a></li> |
| </ul> |
| </li> |
| <li><a href="jsobjects.html#_jsobjects">17. JSObjects</a> |
| <ul class="sectlevel2"> |
| <li><a href="jsobjects.html#_object">17.1. Object</a></li> |
| <li><a href="jsobjects.html#_string">17.2. String</a></li> |
| <li><a href="jsobjects.html#_boolean">17.3. Boolean</a></li> |
| <li><a href="jsobjects.html#_number">17.4. Number</a> |
| <ul class="sectlevel3"> |
| <li><a href="jsobjects.html#_static-attributes">17.4.1. Static Attributes</a></li> |
| </ul> |
| </li> |
| <li><a href="jsobjects.html#function">17.5. Function</a></li> |
| <li><a href="jsobjects.html#_error">17.6. Error</a></li> |
| <li><a href="jsobjects.html#_array">17.7. Array</a></li> |
| <li><a href="jsobjects.html#_date">17.8. Date</a></li> |
| <li><a href="jsobjects.html#_math">17.9. Math</a> |
| <ul class="sectlevel3"> |
| <li><a href="jsobjects.html#static-attributes-1">17.9.1. Static Attributes</a></li> |
| </ul> |
| </li> |
| <li><a href="jsobjects.html#_regexp">17.10. RegExp</a></li> |
| <li><a href="jsobjects.html#_json">17.11. JSON</a></li> |
| </ul> |
| </li> |
| <li><a href="n4js_objects.html#_n4js-objects">18. N4JS Objects</a> |
| <ul class="sectlevel2"> |
| <li><a href="n4js_objects.html#_reflection-model">18.1. Reflection Model</a></li> |
| <li><a href="n4js_objects.html#_error-types">18.2. Error Types</a> |
| <ul class="sectlevel3"> |
| <li><a href="n4js_objects.html#_n4apinotimplemented">18.2.1. N4ApiNotImplemented</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="appendix_a_acronyms.html#_acronyms">Appendix A: Acronyms</a></li> |
| <li><a href="appendix_b_license.html#sec:License">Appendix B: License</a></li> |
| <li><a href="appendix_c_bibliography.html#_bibliography">Appendix C: Bibliography</a></li> |
| </ul> |
| </div> |
| </div> |
| <div id="content"><div class="sect1"> |
| <h2 id="_conversions-and-reflection"><a class="anchor" href="#_conversions-and-reflection"></a><a class="link" href="#_conversions-and-reflection">7. Conversions and Reflection</a></h2> |
| <div class="sectionbody"> |
| <div class="sect2 language-n4js"> |
| <h3 id="_autoboxing-and-coercing"><a class="anchor" href="#_autoboxing-and-coercing"></a><a class="link" href="#_autoboxing-and-coercing">7.1. Autoboxing and Coercing</a></h3> |
| <div class="paragraph"> |
| <p>Coercing is the ability to implicitly cast one (primitive) type to another. |
| Autoboxing is a special kind of coercing in that is the ability to automatically convert a primitive value type, such as <code>string</code>, <code>number</code>, or <code>boolean</code>, |
| to its corresponding Object type version <code>String</code>, <code>Number</code>, <code>Boolean</code>. |
| The capital letters in the latter are an essential distinction.</p> |
| </div> |
| <div class="paragraph"> |
| <p>Conversion between primitives and object-representations of a datatype are not automatic in N4JS. Only in the cases of object-method invocations on a primitive type |
| (for <code>string</code> to call <code>"abc".length</code>, for example) automatic conversion is applied.</p> |
| </div> |
| <div class="paragraph"> |
| <p>Note that N4JS specific primitive types <code>pathselector</code> and <code>i18nkey</code> are handled similarly to <code>string</code>.</p> |
| </div> |
| <div class="sect3"> |
| <h4 id="_coercing"><a class="anchor" href="#_coercing"></a><a class="link" href="#_coercing">7.1.1. Coercing</a></h4> |
| <div class="paragraph"> |
| <p>In [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a</a>], coercing is defined by means of the abstract specification method <code>ToPrimitive</code> [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S9.1)</a>], also see [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S9.10)</a>]). |
| Other conversions, such as <code>ToNumber</code>, are not directly supported but reflected in the typing rules of expressions.</p> |
| </div> |
| <div class="paragraph"> |
| <p>We express absence of automatic coercion here by means of subtype |
| relations:</p> |
| </div> |
| <div class="openblock"> |
| <div class="content"> |
| <math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mtable><mtr><mtd><mfrac><mrow/><mrow><mi>Γ</mi><mo>⊢</mo><mstyle mathvariant="monospace"><mtext>Boolean</mtext></mstyle><mspace width="1.0mm"/><mo>≮</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>boolean</mtext></mstyle></mrow></mfrac><mspace width="3.0mm"/><mfrac><mrow/><mrow><mi>Γ</mi><mo>⊢</mo><mstyle mathvariant="monospace"><mtext>boolean</mtext></mstyle><mspace width="1.0mm"/><mo>≮</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>Boolean</mtext></mstyle></mrow></mfrac></mtd></mtr><mtr><mtd><mfrac><mrow/><mrow><mi>Γ</mi><mo>⊢</mo><mstyle mathvariant="monospace"><mtext>Number</mtext></mstyle><mspace width="1.0mm"/><mo>≮</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>number</mtext></mstyle></mrow></mfrac><mspace width="3.0mm"/><mfrac><mrow/><mrow><mi>Γ</mi><mo>⊢</mo><mstyle mathvariant="monospace"><mtext>number</mtext></mstyle><mspace width="1.0mm"/><mo>≮</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>Number</mtext></mstyle></mrow></mfrac></mtd></mtr><mtr><mtd><mfrac><mrow/><mrow><mi>Γ</mi><mo>⊢</mo><mstyle mathvariant="monospace"><mtext>String</mtext></mstyle><mspace width="1.0mm"/><mo>≮</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>string</mtext></mstyle></mrow></mfrac><mspace width="3.0mm"/><mfrac><mrow/><mrow><mi>Γ</mi><mo>⊢</mo><mstyle mathvariant="monospace"><mtext>string</mtext></mstyle><mspace width="1.0mm"/><mo>≮</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>String</mtext></mstyle></mrow></mfrac></mtd></mtr></mtable></math> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>and for the N4JS specific types:</p> |
| </div> |
| <div class="paragraph"> |
| <p><math xmlns="http://www.w3.org/1998/Math/MathML"><mfrac><mrow/><mrow><mi>Γ</mi><mo>⊢</mo><mstyle mathvariant="monospace"><mtext>pathSelector</mtext></mstyle><mo><</mo><mstyle mathvariant="monospace"><mtext>T</mtext></mstyle><mo>></mo><mspace width="1.0mm"/><mo><</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>string</mtext></mstyle></mrow></mfrac></math><br> |
| <math xmlns="http://www.w3.org/1998/Math/MathML"><mfrac><mrow/><mrow><mi>Γ</mi><mo>⊢</mo><mstyle mathvariant="monospace"><mtext>i18nKey</mtext></mstyle><mspace width="1.0mm"/><mo><</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>string</mtext></mstyle></mrow></mfrac></math></p> |
| </div> |
| <div class="paragraph"> |
| <p>If a conversion between primitive and object type is desired, we require the user of N4JS to actively convert the values. |
| The reason for that is the notably different behavior of object- and primitive-variants of a type in expression evaluation:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code class="language-n4js" data-lang="n4js">var bool: boolean = false; |
| var Bool: Boolean = new Boolean( false ); |
| |
| console.log( bool ? "true" : "false"); // prints "false" |
| console.log( Bool ? "true" : "false"); // prints "true"!</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>Conversion between a primitive type to its object-variant is achieved by the <code>new</code> operator. |
| The <code>valueOf()</code> method converts the object-variant back to a primitive value.</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code class="language-n4js" data-lang="n4js">// objects from literals: |
| var bo: Boolean = new Boolean( true ); // typeof bo: object |
| var no: Number = new Number( 42 ); // typeof no: object |
| var so: String = new String( "foo" ); // typeof so: object |
| |
| // to primitive |
| var b: boolean = bo.valueOf(); // typeof b: boolean -- true |
| var n: number = no.valueOf(); // typeof n: number -- 42 |
| var s: string = so.valueOf(); // typeof s: string -- "foo" |
| |
| // to object-type |
| bo = new Boolean( b ); |
| no = new Number( n ); |
| so = new String( s );</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>Conversion of variables of type <code>Object</code> or from one primitive type to another is expressed in terms of typing rules for expressions. |
| That is, it is not possible to convert any <code>Object</code> to a primitive in general, but it is possible to do so in the context of certain expressions such as additive operator. |
| The applied conversions are described in <a href="#_auto-conversion-of-class-instances">Auto-Conversion of Class Instances</a></p> |
| </div> |
| </div> |
| <div class="sect3"> |
| <h4 id="_autoboxing-of-primitives"><a class="anchor" href="#_autoboxing-of-primitives"></a><a class="link" href="#_autoboxing-of-primitives">7.1.2. Autoboxing of Primitives</a></h4> |
| <div class="paragraph"> |
| <p>In [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a</a>], autoboxing is defined by <code>ToObject</code> [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S9.9)</a>].</p> |
| </div> |
| <div class="paragraph"> |
| <p>Autoboxing is not directly supported in N4JS. Instead, primitive types virtually have the same members as their corresponding object types. |
| It is then possible to use the Autoboxing feature when calling a member. |
| In general, Autoboxing is only supported for accessing built-in read-only (immutable) properties. |
| For example, <code>"some string value".split(" ");</code> is supported but <code>"some string value".foo=1;</code> will be rejected as String does not allow properties to be added (cf. <code>String</code> vs. <code>String+</code>, see <a href="#_dynamic">[_dynamic]</a>).</p> |
| </div> |
| <div class="paragraph"> |
| <p>Autoboxing often leads to problems, in particular in combination with dynamic types – this is why it is not directly supported in N4JS.</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code class="language-n4js" data-lang="n4js">var s: String+ = "Hello"; <i class="conum" data-value="1"></i><b>(1)</b> |
| |
| s.prop = 1; |
| console.log(s.prop); <i class="conum" data-value="2"></i><b>(2)</b></code></pre> |
| </div> |
| </div> |
| <div class="colist arabic"> |
| <table> |
| <tr> |
| <td><i class="conum" data-value="1"></i><b>1</b></td> |
| <td>will produce an error to prevent the following scenario:</td> |
| </tr> |
| <tr> |
| <td><i class="conum" data-value="2"></i><b>2</b></td> |
| <td>prints "undefined"</td> |
| </tr> |
| </table> |
| </div> |
| </div> |
| <div class="sect3"> |
| <h4 id="_autoboxing-of-function-expressions-and-declarations"><a class="anchor" href="#_autoboxing-of-function-expressions-and-declarations"></a><a class="link" href="#_autoboxing-of-function-expressions-and-declarations">7.1.3. Autoboxing of Function Expressions and Declarations</a></h4> |
| <div class="paragraph"> |
| <p>Function expressions and declarations always define an object of type <code>Function</code>, thus coercing or Autoboxing is not required in case of functions:</p> |
| </div> |
| <div class="paragraph"> |
| <p>It is always possible to use a function expression where a <code>Function</code> is required, and to use an object of type <code>Function</code> where a function expression is expected. |
| This is only possible if the function signatures are subtype-compatible, see <a href="functions.html#_function-type">Function Type</a> for details.</p> |
| </div> |
| <div class="paragraph"> |
| <p>Still, it is always possible to call members of <code>Function</code>, e.g., <code>function(){}.length()</code>.</p> |
| </div> |
| </div> |
| </div> |
| <div class="sect2 language-n4js"> |
| <h3 id="_auto-conversion-of-objects"><a class="anchor" href="#_auto-conversion-of-objects"></a><a class="link" href="#_auto-conversion-of-objects">7.2. Auto-Conversion of Objects</a></h3> |
| <div class="sect3"> |
| <h4 id="_auto-conversion-of-class-instances"><a class="anchor" href="#_auto-conversion-of-class-instances"></a><a class="link" href="#_auto-conversion-of-class-instances">7.2.1. Auto-Conversion of Class Instances</a></h4> |
| <div class="paragraph"> |
| <p>All classes defined in N4JS modules implicitly subclass <code>N4Object</code>, which is a plain JavaScript Object type. |
| The same auto-conversion rules defined for JavaScript <code>Object</code> therefore apply to <code>N4Object</code> instances as well.</p> |
| </div> |
| <div class="paragraph"> |
| <p>The basic conversion uses the abstract JavaScript function <code>ToPrimitive</code> [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S9.1)</a>], which relays on the specification method <code>Object</code> [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S8.12.8)</a>]. |
| <code>DefaultValue</code> calls <code>valueOf</code> or <code>toString</code> methods if they are defined by the class (in the <code>methods</code>-builder).</p> |
| </div> |
| <div class="paragraph"> |
| <p>Note that according to the [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a</a>], in most cases, objects are first converted into primitives. |
| That is, in most cases, no extra hint is passed to <code>DefaultValue</code>. Thus <code>valueOf</code> usually takes precedence over toString as demonstrated in the following example:</p> |
| </div> |
| <div class="exampleblock"> |
| <div class="title">Example 71. Auto-Conversion</div> |
| <div class="content"> |
| <div class="paragraph"> |
| <p>Assume some classes and corresponding instances defined as follows:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code class="language-n4js" data-lang="n4js">class A {} |
| class B{ |
| @Override public toString(): string { return "MyB"} |
| } |
| class C{ |
| @Override public valueOf(): any { return 10} |
| } |
| class D{ |
| @Override public toString(): string { return "MyD"} |
| @Override public valueOf(): any { return 20} |
| } |
| var a = new A(), b = new B(), c = new C(), d = new D();</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>Instances of these classes will be converted as demonstrated as follows:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code class="language-n4js" data-lang="n4js">console.log(a+""); // [object Object] |
| console.log(a+1); // [object Object]1 |
| |
| console.log(""+b+""); // MyB |
| console.log(1+b+1); // 1MyB1 |
| |
| console.log(c+""); // 10 |
| console.log(c+1); // 11 |
| |
| console.log(d+""); // 20 |
| console.log(d+1); // 21</code></pre> |
| </div> |
| </div> |
| </div> |
| </div> |
| <div class="sect4"> |
| <h5 id="_auto-conversion-of-interface-instances"><a class="anchor" href="#_auto-conversion-of-interface-instances"></a><a class="link" href="#_auto-conversion-of-interface-instances">7.2.1.1. Auto-Conversion of Interface Instances</a></h5> |
| <div class="paragraph"> |
| <p>Instances of interfaces actually are instances of classes at runtime. |
| The auto-conversion rules described in <a href="#_auto-conversion-of-class-instances">Auto-Conversion of Class Instances</a> are applied to instances declared as instances of interfaces as well.</p> |
| </div> |
| </div> |
| </div> |
| <div class="sect3"> |
| <h4 id="_auto-conversion-of-enum-literals"><a class="anchor" href="#_auto-conversion-of-enum-literals"></a><a class="link" href="#_auto-conversion-of-enum-literals">7.2.2. Auto-Conversion of Enum Literals</a></h4> |
| <div class="paragraph"> |
| <p>Enumeration values are objects and thus follow the behavior for ECMAScript <code>Object</code> and <code>Function</code>. |
| They have a custom <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>t</mi><mi>o</mi><mi>S</mi><mi>t</mi><mi>r</mi><mi>i</mi><mi>n</mi><mi>g</mi></math> method which returns the name of the enumeration value.</p> |
| </div> |
| </div> |
| </div> |
| <div class="sect2 language-n4js"> |
| <h3 id="_type-cast-and-type-check"><a class="anchor" href="#_type-cast-and-type-check"></a><a class="link" href="#_type-cast-and-type-check">7.3. Type Cast and Type Check</a></h3> |
| <div class="sect3"> |
| <h4 id="_type-cast"><a class="anchor" href="#_type-cast"></a><a class="link" href="#_type-cast">7.3.1. Type Cast</a></h4> |
| <div class="literalblock"> |
| <div class="content"> |
| <pre>(IDEBUG-56): Casting to TypeVars</pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>Type casts are expressed with the cast expression (<code>as</code>), see <a href="expressions.html#_cast-as-expression">Cast (As) Expression</a> for details.</p> |
| </div> |
| <div class="paragraph"> |
| <p>We first define helper rules for the type cast constraints as follows:</p> |
| </div> |
| <div class="openblock"> |
| <div class="content"> |
| <math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mtable><mtr><mtd><mfrac><mrow><mi>μ</mi><mfenced close=")" open="("><mi>T</mi></mfenced><mo>∈</mo><mfenced close="}" open="{"><mstyle mathvariant="monospace"><mtext>TEnum</mtext></mstyle><mstyle mathvariant="monospace"><mtext>Class</mtext></mstyle><mstyle mathvariant="monospace"><mtext>Primitive</mtext></mstyle><mstyle mathvariant="monospace"><mtext>ObjectType</mtext></mstyle></mfenced></mrow><mrow><mi>i</mi><mi>s</mi><mi>C</mi><mi>P</mi><mi>O</mi><mi>E</mi><mfenced close=")" open="("><mi>T</mi></mfenced></mrow></mfrac></mtd></mtr><mtr><mtd><mfrac><mrow><mi>μ</mi><mi>T</mi><mo>∈</mo><mfenced close="}" open="{"><mstyle mathvariant="monospace"><mtext>ClassifierType</mtext></mstyle><mstyle mathvariant="monospace"><mtext>TypeType</mtext></mstyle></mfenced><mo>∧</mo><mi>μ</mi><mfenced close=")" open="("><mrow><mi>T</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi></mrow></mfenced><mo>≠</mo><mstyle mathvariant="monospace"><mtext>TypeVariable</mtext></mstyle></mrow><mrow><mi>i</mi><mi>s</mi><mi>C</mi><mi>P</mi><mi>O</mi><mi>E</mi><mfenced close=")" open="("><mi>T</mi></mfenced></mrow></mfrac></mtd></mtr><mtr><mtd><mfrac><mrow><mi>μ</mi><mfenced close=")" open="("><mi>T</mi></mfenced><mo>∈</mo><mfenced close="}" open="{"><mstyle mathvariant="monospace"><mtext>Interface</mtext></mstyle></mfenced></mrow><mrow><mi>i</mi><mi>s</mi><mi>I</mi><mi>n</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>f</mi><mi>a</mi><mi>c</mi><mi>e</mi><mfenced close=")" open="("><mi>T</mi></mfenced></mrow></mfrac></mtd></mtr><mtr><mtd><mfrac><mrow><mi>μ</mi><mfenced close=")" open="("><mi>T</mi></mfenced><mo>=</mo><mstyle mathvariant="monospace"><mtext>TypeVariable</mtext></mstyle><mo>∧</mo><mi>T</mi><mo>.</mo><mi>u</mi><mi>p</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>B</mi><mi>o</mi><mi>u</mi><mi>n</mi><mi>d</mi><mi>s</mi><mo>≠</mo><mi>∅</mi></mrow><mrow><mi>i</mi><mi>s</mi><mi>B</mi><mi>o</mi><mi>u</mi><mi>n</mi><mi>d</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>V</mi><mi>a</mi><mi>r</mi><mfenced close=")" open="("><mi>T</mi></mfenced></mrow></mfrac></mtd></mtr><mtr><mtd><mfrac><mrow><mi>μ</mi><mfenced close=")" open="("><mi>T</mi></mfenced><mo>∈</mo><mfenced close="}" open="{"><mrow><mi> </mi><mstyle mathvariant="monospace"><mtext>TEnum</mtext></mstyle></mrow><mstyle mathvariant="monospace"><mtext>Primitive</mtext></mstyle></mfenced><mo>∨</mo><mfenced close="}" open="("><mrow><mi>μ</mi><mfenced close=")" open="("><mi>T</mi></mfenced><mo>=</mo><mstyle mathvariant="monospace"><mtext>Class</mtext></mstyle><mo>∧</mo><mi>T</mi><mo>.</mo><mi>e</mi><mi>x</mi><mi>t</mi><mi>e</mi><mi>n</mi><mi>s</mi><mi>i</mi><mi>b</mi><mi>i</mi><mi>l</mi><mi>i</mi><mi>t</mi><mi>y</mi><mo>=</mo><mstyle mathvariant="monospace"><mtext>final</mtext></mstyle></mrow></mfenced><mo>)</mo></mrow><mrow><mi>i</mi><mi>s</mi><mi>F</mi><mi>i</mi><mi>n</mi><mi>a</mi><mi>l</mi><mi>B</mi><mi>y</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi><mfenced close=")" open="("><mi>T</mi></mfenced></mrow></mfrac></mtd></mtr></mtable></math> |
| </div> |
| </div> |
| <div class="openblock requirement"> |
| <div class="content"> |
| <div class="paragraph"> |
| <p><a id="Req-IDE-89"></a><strong>Req. IDE-89:</strong> <a href="#Req-IDE-89">Cast Validation At Compile Time</a> (ver. 1)</p> |
| </div> |
| <div class="paragraph"> |
| <p>Given a type cast expression <code>e</code> in which |
| <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>Γ</mi><mo>⊢</mo><mi>e</mi><mo>.</mo><mi>e</mi><mi>x</mi><mi>p</mi><mi>r</mi><mi>:</mi><mi>S</mi></math> and and target type <code>T</code>, the |
| following constraints must hold:</p> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic"> |
| <li> |
| <p><code>T</code> must be a classifier, enum, primitive, function type expression, classifier type, type variable, union or intersection type:</p> |
| <div class="paragraph"> |
| <p><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>μ</mi><mfenced close=")" open="("><mi>T</mi></mfenced><mo>∈</mo><mspace width="3.0mm"/><mrow><mo>{</mo><mstyle mathvariant="monospace"><mtext>any</mtext></mstyle><mo>,</mo><mstyle mathvariant="monospace"><mtext>Class</mtext></mstyle><mo>,</mo><mstyle mathvariant="monospace"><mtext>Interface</mtext></mstyle><mo>,</mo><mstyle mathvariant="monospace"><mtext>Enum</mtext></mstyle><mo>,</mo><mstyle mathvariant="monospace"><mtext>Primitive</mtext></mstyle><mo>,</mo><mstyle mathvariant="monospace"><mtext>ObjectType</mtext></mstyle><mo>,</mo></mrow></math><br> |
| <math xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mspace width="3.0mm"/><mstyle mathvariant="monospace"><mtext>FunctionTypeExpression</mtext></mstyle><mo>,</mo><mstyle mathvariant="monospace"><mtext>ClassifierType</mtext></mstyle><mo>,</mo><mstyle mathvariant="monospace"><mtext>TypeVariable</mtext></mstyle><mo>,</mo><mstyle mathvariant="monospace"><mtext>Union</mtext></mstyle><mo>,</mo><mstyle mathvariant="monospace"><mtext>Intersection</mtext></mstyle><mo>}</mo></mrow></math></p> |
| </div> |
| </li> |
| <li> |
| <p>if <code>S</code> is a subtype of <code>T</code>, the cast is unnecessary and a warning will be generated.</p> |
| </li> |
| <li> |
| <p>if <code>S</code> and <code>T</code> are classes, enums or primitive types, then <code>T</code> must be a subtype of <code>S</code>. |
| This is also true if <code>T</code> is an interface and the type of <code>S</code> cannot have subtypes, or vice versa.</p> |
| <div class="paragraph"> |
| <p><math xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mo>(</mo><mi>i</mi><mi>s</mi><mi>C</mi><mi>P</mi><mi>O</mi><mi>E</mi><mfenced close=")" open="("><mi>T</mi></mfenced></mrow></math><br> |
| <math xmlns="http://www.w3.org/1998/Math/MathML"><mspace width="2.0em"/><mo>∧</mo><mrow><mo>(</mo><mi>i</mi><mi>s</mi><mi>C</mi><mi>P</mi><mi>O</mi><mi>E</mi><mfenced close=")" open="("><mi>S</mi></mfenced></mrow></math><br> |
| <math xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mspace width="4.0em"/><mo>∨</mo><mfenced close=")" open="("><mrow><mi>μ</mi><mfenced close=")" open="("><mi>S</mi></mfenced><mo>=</mo><mstyle mathvariant="monospace"><mtext>Intersection</mtext></mstyle><mo>∧</mo><mo>∃</mo><msup><mi>S</mi><mi>'</mi></msup><mo>∈</mo><mi>S</mi><mi>:</mi><mi>i</mi><mi>s</mi><mi>C</mi><mi>P</mi><mi>O</mi><mi>E</mi><mfenced close=")" open="("><msup><mi>S</mi><mi>'</mi></msup></mfenced></mrow></mfenced><mo>)</mo></mrow></math><br> |
| <math xmlns="http://www.w3.org/1998/Math/MathML"><mo>∨</mo><mfenced close=")" open="("><mrow><mi>i</mi><mi>s</mi><mi>I</mi><mi>n</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>f</mi><mi>a</mi><mi>c</mi><mi>e</mi><mfenced close=")" open="("><mi>T</mi></mfenced><mo>∧</mo><mi>i</mi><mi>s</mi><mi>F</mi><mi>i</mi><mi>n</mi><mi>a</mi><mi>l</mi><mi>B</mi><mi>y</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi><mfenced close=")" open="("><mi>S</mi></mfenced></mrow></mfenced></math><br> |
| <math xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mo>∨</mo><mfenced close=")" open="("><mrow><mi>i</mi><mi>s</mi><mi>F</mi><mi>i</mi><mi>n</mi><mi>a</mi><mi>l</mi><mi>B</mi><mi>y</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi><mfenced close=")" open="("><mi>T</mi></mfenced><mo>∧</mo><mi>i</mi><mi>s</mi><mi>I</mi><mi>n</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>f</mi><mi>a</mi><mi>c</mi><mi>e</mi><mfenced close=")" open="("><mi>S</mi></mfenced></mrow></mfenced><mo>)</mo></mrow><mo>→</mo><mi>Γ</mi><mo>⊢</mo><mi>T</mi><mo><</mo><mi>:</mi><mi>S</mi></math></p> |
| </div> |
| </li> |
| <li> |
| <p>if <code>S</code> is a class, enum or primitive type and <code>T</code> is a type-variable, then for each given boundary <math xmlns="http://www.w3.org/1998/Math/MathML"><msubsup><mi>T</mi><mi>i</mi><mrow><mi>u</mi><mi>p</mi></mrow></msubsup></math> of <code>T</code> |
| of type class, enum or primitive <code>S</code> must be a member of the type hierarchy: <sup class="footnote">[<a id="_footnoteref_47" class="footnote" href="appendix_c_bibliography.html#_footnote_47" title="View footnote.">47</a>]</sup></p> |
| <div class="paragraph"> |
| <p><math xmlns="http://www.w3.org/1998/Math/MathML"><mfenced close=")" open="("><mrow><mi>i</mi><mi>s</mi><mi>B</mi><mi>o</mi><mi>u</mi><mi>n</mi><mi>d</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>V</mi><mi>a</mi><mi>r</mi><mfenced close=")" open="("><mi>T</mi></mfenced><mo>∧</mo><mi>i</mi><mi>s</mi><mi>C</mi><mi>P</mi><mi>O</mi><mi>E</mi><mfenced close=")" open="("><mi>S</mi></mfenced></mrow></mfenced></math><br> |
| <math xmlns="http://www.w3.org/1998/Math/MathML"><mo>→</mo><msub><mo>∀</mo><mrow><msubsup><mi>T</mi><mi>i</mi><mrow><mi>u</mi><mi>p</mi></mrow></msubsup><mo>∈</mo><mi>T</mi><mo>.</mo><mi>u</mi><mi>p</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>B</mi><mi>o</mi><mi>u</mi><mi>n</mi><mi>d</mi><mi>s</mi></mrow></msub><mrow><mo>(</mo><mi>i</mi><mi>s</mi><mi>C</mi><mi>P</mi><mi>O</mi><mi>E</mi><mfenced close=")" open="("><msubsup><mi>T</mi><mi>i</mi><mrow><mi>u</mi><mi>p</mi></mrow></msubsup></mfenced><mo>→</mo><mi>Γ</mi><mo>⊢</mo><mrow><mo>(</mo><mrow><mrow><msubsup><mi>T</mi><mi>i</mi><mrow><mi>u</mi><mi>p</mi></mrow></msubsup><mo><</mo><mi>:</mi><mi>S</mi><mo>∨</mo><msubsup><mi>T</mi><mi>i</mi><mrow><mi>u</mi><mi>p</mi></mrow></msubsup><mi>:</mi><mo>></mo><mi>S</mi><mo>)</mo></mrow><mo>)</mo></mrow></mrow></mrow></math></p> |
| </div> |
| </li> |
| <li> |
| <p>if <code>S</code> is a union or intersection type, then the type cast is valid if it is valid for at least one element of <code>S</code>.</p> |
| </li> |
| <li> |
| <p>if <code>S</code> and <code>T</code> are generics, and if <math xmlns="http://www.w3.org/1998/Math/MathML"><msup><mi>S</mi><mn>0</mn></msup><mo>=</mo><msup><mi>T</mi><mn>0</mn></msup></math>, |
| a cast is possible if type arguments are sub- or supertypes of each other: <sup class="footnote">[<a id="_footnoteref_48" class="footnote" href="appendix_c_bibliography.html#_footnote_48" title="View footnote.">48</a>]</sup></p> |
| <div class="paragraph"> |
| <p><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>μ</mi><mfenced close=")" open="("><mi>S</mi></mfenced><mo>=</mo><mstyle mathvariant="monospace"><mtext>Classifier</mtext></mstyle><mo>∧</mo><mi>μ</mi><mfenced close=")" open="("><mi>T</mi></mfenced><mo>=</mo><mstyle mathvariant="monospace"><mtext>Classifier</mtext></mstyle><mo>∧</mo><msup><mi>S</mi><mn>0</mn></msup><mo>=</mo><msup><mi>T</mi><mn>0</mn></msup><mo>→</mo></math><br> |
| <math xmlns="http://www.w3.org/1998/Math/MathML"><mspace width="2.0em"/><mrow><mo>(</mo><mrow><mo>∀</mo><mi> </mi><mi>S</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>A</mi><mi>r</mi><msub><mi>g</mi><mi>i</mi></msub><mo><</mo><mi>:</mi><mi>T</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>A</mi><mi>r</mi><msub><mi>g</mi><mi>i</mi></msub><mo>)</mo></mrow><mo>∨</mo><mrow><mo>(</mo><mrow><mo>∀</mo><mi> </mi><mi>T</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>A</mi><mi>r</mi><msub><mi>g</mi><mi>i</mi></msub><mo><</mo><mi>:</mi><mi>S</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>A</mi><mi>r</mi><msub><mi>g</mi><mi>i</mi></msub><mo>)</mo></mrow></mrow></mrow></math></p> |
| </div> |
| </li> |
| <li> |
| <p>If <code>T</code> is a union type, then the type cast is valid if it is valid for at least one element of <code>T</code>.</p> |
| </li> |
| <li> |
| <p>If <code>T</code> is an intersection type, then the type cast is valid if it is valid for all elements of <code>T</code>.</p> |
| </li> |
| </ol> |
| </div> |
| <div class="admonitionblock note"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-note" title=""></i> |
| </td> |
| <td class="content"> |
| <code>any</code> is a supertype of all other types, thus it is always possible to cast a variable of type <code>any</code> to other (non-composed) types. |
| </td> |
| </tr> |
| </table> |
| </div> |
| </div> |
| </div> |
| </div> |
| <div class="sect3"> |
| <h4 id="_type-check"><a class="anchor" href="#_type-check"></a><a class="link" href="#_type-check">7.3.2. Type Check</a></h4> |
| <div class="paragraph"> |
| <p>There are basically two ways of testing the type of a variable: <code>typeof</code> and <code>instanceof</code>. |
| N4JS supports type comparison via the ECMAScript <code>instanceof</code> operator. |
| The operator <code>instanceof</code> retains its standard ECMAScript behavior (e.g. checking whether a value is an instance of a constructor function), but has additional functionality when used with N4JS types.</p> |
| </div> |
| <div class="paragraph"> |
| <p>When used with an N4JS class, <code>instanceof</code> also supports checking against an interface. For N4JS enumeration values, it can be used to check whether the value is part of a specific enumeration.</p> |
| </div> |
| <div class="paragraph"> |
| <p><code>typeof</code> only returns a string with the name of the ECMAScript type, which is <code>Object</code> for all class instances.</p> |
| </div> |
| <div class="paragraph"> |
| <p>N4JS specific <code>string</code> types, that is <code>pathSelector</code> and <code>i18nkey</code> cannot be tested during runtime. |
| These types, therefore, must not be used in <code>instanceof</code> expressions. |
| The same is true for string-based enums and arrays which cannot be tested during runtime, thus string-based enum and array types are not permitted on the right-hand side of <code>instancesof</code> constructs. |
| For all types for which the evaluation result of <code>instanceof</code> could be computed at compile time, the check is unnecessary and thus it is refused by the compiler. |
| Using structural types on the right-hand side of <code>instancesof</code> constructs is also not permitted.</p> |
| </div> |
| <div class="paragraph"> |
| <p>In order to avoid errors at runtime, the <code>instanceof</code> operator defines appropriate constraints, see <a href="expressions.html#_relational-expression">Relational Expression</a> for details.</p> |
| </div> |
| <div class="exampleblock"> |
| <div class="title">Example 72. Type Check Example</div> |
| <div class="content"> |
| <div class="paragraph"> |
| <p>Given the following classes and variable:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code class="language-n4js" data-lang="n4js">interface I{} |
| class S{} |
| class Sub extends S implements I{} |
| |
| var x = new Sub();</code></pre> |
| </div> |
| </div> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p><code>typeof x</code> will simply return <code>object</code>. The following table shows the difference between plain JavaScript <code>instanceof</code> and N4JS’s <code>instanceof</code>:</p> |
| </div> |
| <table class="tableblock frame-all grid-all spread"> |
| <colgroup> |
| <col style="width: 33.3333%;"> |
| <col style="width: 33.3333%;"> |
| <col style="width: 33.3334%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Check</th> |
| <th class="tableblock halign-center valign-top">JavaScript</th> |
| <th class="tableblock halign-center valign-top">N4JS</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>x instanceof Sub</code></p></td> |
| <td class="tableblock halign-center valign-top"><p class="tableblock"><code>true</code></p></td> |
| <td class="tableblock halign-center valign-top"><p class="tableblock"><code>true</code></p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>x instanceof S</code></p></td> |
| <td class="tableblock halign-center valign-top"><p class="tableblock"><code>true</code></p></td> |
| <td class="tableblock halign-center valign-top"><p class="tableblock"><code>true</code></p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>x instanceof I</code></p></td> |
| <td class="tableblock halign-center valign-top"><p class="tableblock"><code>false</code></p></td> |
| <td class="tableblock halign-center valign-top"><p class="tableblock"><code>true</code></p></td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| </div> |
| <div class="sect2 language-n4js"> |
| <h3 id="_reflection-meta-information"><a class="anchor" href="#_reflection-meta-information"></a><a class="link" href="#_reflection-meta-information">7.4. Reflection meta-information</a></h3> |
| <div class="paragraph"> |
| <p>All N4JS classes, interfaces and enumerations provide meta-information |
| that is used by the runtime and standard library. |
| All classifiers (including enums) provide meta-information by means of a static getter <code>n4type</code>. |
| Since it is static getter, it is actually an instance getter of the |
| constructor (or classifier) of a type, which is the only way to retrieve |
| that information in case of interfaces. For enums, this can be retrieved |
| from instances as well.</p> |
| </div> |
| <div class="paragraph"> |
| <p>This getter is of type <code>N4Class</code> which is a built-in type just like <code>N4Object</code>. It contains the following members:</p> |
| </div> |
| <div class="dlist"> |
| <dl> |
| <dt class="hdlist1"><code>fqn</code> </dt> |
| <dd> |
| <p>The <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>F</mi><mi>Q</mi><mi>N</mi></math> of the type.</p> |
| </dd> |
| <dt class="hdlist1"><code>n4superType</code> </dt> |
| <dd> |
| <p>The <code>N4Class</code> of the supertype, may be null if supertype is a not an <code>N4Class</code>.</p> |
| </dd> |
| <dt class="hdlist1"><code>allImplementedInterfaces</code> </dt> |
| <dd> |
| <p>List of The <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>F</mi><mi>Q</mi><mi>N</mi></math> of implemented interfaces (transitively |
| but without interfaces implemented by supertype)</p> |
| </dd> |
| <dt class="hdlist1"><code>get isClass</code> </dt> |
| <dd> |
| <p>True if the type is an N4Class.</p> |
| </dd> |
| <dt class="hdlist1"><code>get isInterface</code> </dt> |
| <dd> |
| <p>True if the type is an N4Interface.</p> |
| </dd> |
| </dl> |
| </div> |
| <div class="sect3"> |
| <h4 id="_reflection-for-classes"><a class="anchor" href="#_reflection-for-classes"></a><a class="link" href="#_reflection-for-classes">7.4.1. Reflection for Classes</a></h4> |
| <div class="paragraph"> |
| <p>The meta-information for classes is available by means of <code>N4Object</code>’s static |
| getter <code>n4type</code>. Since it is static getter, it is actually an instance getter of the constructor of a type.</p> |
| </div> |
| <div class="paragraph"> |
| <p>In addition, the static method <code>of</code> in <code>N4Type</code> is available to retrieve the meta-information for a given instance or |
| constructor. This also allows to retrieve meta-information directly for an instance of some class <code>C</code> without having |
| the constructor of <code>C</code> available, for example because the constructor is not accessible.</p> |
| </div> |
| <div class="exampleblock"> |
| <div class="title">Example 73. Reflection with <code>N4class</code></div> |
| <div class="content"> |
| <div class="paragraph"> |
| <p>This example demonstrates how these reflective features are accessed:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code class="language-n4js" data-lang="n4js">class A {} |
| class B extends A {} |
| var b = new B(); |
| console.log(B.n4type.fqn); |
| console.log(b.constructor.n4type.fqn); |
| console.log(b.constructor.n4type.n4superType.fqn); |
| console.log(N4Type.of(b)); |
| console.log(N4Type.of(B.n4type).fqn);</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>Assuming this code is defined in file <code>A</code>, this will output</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code class="language-n4js" data-lang="n4js">A.B |
| A.B |
| A.A |
| A.B |
| N4BuiltInClasses.N4Class</code></pre> |
| </div> |
| </div> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>The built-in types <code>N4Object</code> and <code>N4Class</code> are also accessible. |
| They are not defined in a module, thus their <a href="appendix_a_acronyms.html#_acronyms">FQN</a> returns only their simple name.</p> |
| </div> |
| <div class="exampleblock"> |
| <div class="title">Example 74. Reflection with Built-In Types</div> |
| <div class="content"> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code class="language-n4js" data-lang="n4js">console.log('N4Object.n4class.fqn: ' + N4Object.n4class.fqn) |
| console.log('N4Class.n4class.fqn: ' + N4Class.n4class.fqn) |
| |
| class A {} |
| console.log('A.n4class.fqn: ' + A.n4class.fqn) |
| console.log('A.n4class.n4superType.fqn: ' + A.n4class.n4superType.fqn)</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>Assuming this code is defined in file <code>A</code>, this will output</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code class="language-n4js" data-lang="n4js">N4Object.n4class.fqn: N4Object |
| N4Class.n4class.fqn: N4Class |
| A.n4class.fqn: A.A |
| A.n4class.n4superType.fqn: N4Object</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>Note that classes extending <code>Object</code> do not provide the static <code>n4class</code> getter, hat is</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code class="language-n4js" data-lang="n4js">class B extends Object {} |
| console.log('B.n4class.fqn: ' + B.n4class.fqn)</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>would issue an error as cannot be resolved.</p> |
| </div> |
| </div> |
| </div> |
| <div class="exampleblock"> |
| <div class="title">Example 75. N4Class.of</div> |
| <div class="content"> |
| <div class="paragraph"> |
| <p>The type has a method to retrieve the meta-information from instances (i.e. or enumeration literals using ) |
| without using the constructor.</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code class="language-n4js" data-lang="n4js">class C { } |
| interface I {} class IImpl implements I {} |
| enum E { L } |
| |
| var c: C = new C(); |
| var i: I = new IImpl(); |
| var e: E = E.L; |
| |
| console.log(C.n4type.fqn); |
| console.log(N4Class.of(c).fqn); |
| |
| console.log(I.n4type.fqn); |
| console.log(N4Class.of(i).fqn); |
| |
| console.log(E.n4type.fqn); |
| console.log(N4EnumType.of(e).fqn);</code></pre> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| <div class="sect3"> |
| <h4 id="_reflection-for-interfaces"><a class="anchor" href="#_reflection-for-interfaces"></a><a class="link" href="#_reflection-for-interfaces">7.4.2. Reflection for Interfaces</a></h4> |
| <div class="paragraph"> |
| <p>The meta-information of an interface <code>X</code> is available via getter <code>n4class</code> defined in the <code>type{X}</code>. |
| This field is of type <code>N4Class</code> as well. |
| Since an interface cannot have a super classs, the property <code>n4superTypes</code> will always be empty. |
| Calling <code>isInterface</code> respectively on the returned <code>N4Class</code> instance will return true.</p> |
| </div> |
| </div> |
| <div class="sect3"> |
| <h4 id="_reflection-for-enumerations"><a class="anchor" href="#_reflection-for-enumerations"></a><a class="link" href="#_reflection-for-enumerations">7.4.3. Reflection for Enumerations</a></h4> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code class="language-n4js" data-lang="n4js">var n: number; var b: boolean; var s: string;</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>The meta-information for enumerations is available by means of the getter <code>n4class</code>, either statically by using the enumeration type or (in terms of an instance getter) via a literal. |
| Calling <code>isEnum</code> on the returned <code>N4Class</code> instance will return true.</p> |
| </div> |
| </div> |
| </div> |
| <div class="sect2 language-n4js"> |
| <h3 id="_conversion-of-primitive-types"><a class="anchor" href="#_conversion-of-primitive-types"></a><a class="link" href="#_conversion-of-primitive-types">7.5. Conversion of primitive types</a></h3> |
| <div class="paragraph"> |
| <p>Conversion between primitives is given as follows:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code class="language-n4js" data-lang="n4js">var n: number; var b: boolean; var s: string;</code></pre> |
| </div> |
| </div> |
| <table class="tableblock frame-all grid-all spread"> |
| <colgroup> |
| <col style="width: 11.1111%;"> |
| <col style="width: 11.1111%;"> |
| <col style="width: 44.4444%;"> |
| <col style="width: 33.3334%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-center valign-middle">From</th> |
| <th class="tableblock halign-center valign-middle">To</th> |
| <th class="tableblock halign-left valign-middle">Conversion</th> |
| <th class="tableblock halign-center valign-top">Example</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-center valign-middle"><p class="tableblock"><code>string</code></p></td> |
| <td class="tableblock halign-center valign-middle"><p class="tableblock"><code>number</code></p></td> |
| <td class="tableblock halign-left valign-middle"><p class="tableblock"><code>Number…​</code></p></td> |
| <td class="tableblock halign-left valign-top"><div><div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code class="language-n4js" data-lang="n4js">n = Number("42");//42</code></pre> |
| </div> |
| </div></div></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-center valign-middle"><p class="tableblock"><code>string</code></p></td> |
| <td class="tableblock halign-center valign-middle"><p class="tableblock"><code>boolean</code></p></td> |
| <td class="tableblock halign-left valign-middle"><p class="tableblock"><code>N4Primitives.parseBoolean(…​)</code></p></td> |
| <td class="tableblock halign-left valign-top"><div><div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code class="language-n4js" data-lang="n4js"> b=N4Primitives.parseBoolean("false");</code></pre> |
| </div> |
| </div></div></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-center valign-middle"><p class="tableblock"><code>number</code></p></td> |
| <td class="tableblock halign-center valign-middle"><p class="tableblock"><code>boolean</code></p></td> |
| <td class="tableblock halign-left valign-middle"><p class="tableblock"><code>Boolean(…​)</code></p></td> |
| <td class="tableblock halign-left valign-top"><div><div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code class="language-n4js" data-lang="n4js">b=Boolean(17.5); //true</code></pre> |
| </div> |
| </div></div></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-center valign-middle"><p class="tableblock"><code>number</code></p></td> |
| <td class="tableblock halign-center valign-middle"><p class="tableblock"><code>string</code></p></td> |
| <td class="tableblock halign-left valign-middle"><p class="tableblock"><code>Number.toString()</code></p></td> |
| <td class="tableblock halign-left valign-top"><div><div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code class="language-n4js" data-lang="n4js">s=42.toString(); //"42"</code></pre> |
| </div> |
| </div></div></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-center valign-middle"><p class="tableblock"><code>boolean</code></p></td> |
| <td class="tableblock halign-center valign-middle"><p class="tableblock"><code>number</code></p></td> |
| <td class="tableblock halign-left valign-middle"><p class="tableblock"><code>N4Primitives.toNumber(…​)</code></p></td> |
| <td class="tableblock halign-left valign-top"><div><div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code class="language-n4js" data-lang="n4js">n=N4Primitives.toNumber(true);</code></pre> |
| </div> |
| </div></div></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-center valign-middle"><p class="tableblock"><code>boolean</code></p></td> |
| <td class="tableblock halign-center valign-middle"><p class="tableblock"><code>string</code></p></td> |
| <td class="tableblock halign-left valign-middle"><p class="tableblock"><code>Boolean.toString()</code></p></td> |
| <td class="tableblock halign-left valign-top"><div><div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code class="language-n4js" data-lang="n4js"> s=true.toString();//"true" }</code></pre> |
| </div> |
| </div></div></td> |
| </tr> |
| </tbody> |
| </table> |
| <div class="paragraph"> |
| <p>Remarks:</p> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic"> |
| <li> |
| <p>ECMAScript doesn’t define explicit conversion from string content. |
| Implicit handling states all strings with <math xmlns="http://www.w3.org/1998/Math/MathML"><mo>></mo><mn>0</mn><mo>=</mo><mo>=</mo><mi>t</mi><mi>r</mi><mi>u</mi><mi>e</mi></math>. <code>N4Primitives.parseBoolean(x)</code> yields true for <code>x.trim().toLowerCase().equals("true")</code></p> |
| </li> |
| <li> |
| <p>The call to <code>Boolean(..)</code> for the arguments <code>0</code>, <code>-0</code>, <code>null</code>, <code>false</code>, <code>NaN</code>, <code>undefined</code> and <code>""</code> evaluate to <code>false</code>. |
| All other values evaluate to <code>true</code>.</p> |
| </li> |
| <li> |
| <p><code>Number</code> has several methods for converting a value to string [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S15.7.4)</a>]: <code>toExponential()</code>, to <code>Fixed()</code>, <code>toPrecision()</code>.</p> |
| </li> |
| <li> |
| <p>ECMAScript doesn’t define explicit conversion from boolean to number. |
| Implicit handling states true <math xmlns="http://www.w3.org/1998/Math/MathML"><mo>→</mo></math> 1 and false <math xmlns="http://www.w3.org/1998/Math/MathML"><mo>→</mo></math> 0, which <code>N4Primitives.toNumber()</code> yields.</p> |
| </li> |
| </ol> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| <div id="footer"> |
| <div id="footer-text"> |
| Version 0.9<br> |
| Last updated 2019-08-08 13:15:33 CEST |
| </div> |
| </div> |
| <!-- ************* docinfo-footer *************************************************************** --> |
| <div class="Grid social" style="color:#d5dfea"> |
| <div class="Cell Cell--2-12 m-Cell--withMargin"> |
| <h2>Quick Links</h2> |
| <ul> |
| <li><a href="../downloads.html">Download</a></li> |
| <li><a href="../userguides/index.html">Documentation</a></li> |
| <li><a href="https://github.com/eclipse/n4js/">Source</a></li> |
| <li><a href="https://github.com/eclipse/n4js/issues">Issues</a></li> |
| </ul> |
| </div> |
| <div class="Cell Cell--2-12 m-Cell--withMargin"> |
| <br/><br/> |
| <ul> |
| <li><a href="https://www.eclipse.org/forums/index.php/f/365/">Forum</a></li> |
| <li><a href="http://n4js.blogspot.de/">Blog</a></li> |
| <li><a href="https://dev.eclipse.org/mailman/listinfo/n4js-dev">Mailing List</a></li> |
| <li><a href="https://projects.eclipse.org/projects/technology.n4js">Eclipse Project Page</a></li> |
| <li><a href="https://twitter.com/n4jsdev">Tweets by n4jsdev</a></li> |
| </ul> |
| </div> |
| <div class="Cell Cell--2-12 m-Cell--withMargin"> |
| <br/><br/> |
| <ul> |
| <li><a href="http://www.eclipse.org/">Eclipse Home</a></li> |
| <li><a href="http://www.eclipse.org/legal/privacy.php">Privacy Policy</a></li> |
| <li><a href="http://www.eclipse.org/legal/termsofuse.php">Terms of Use</a></li> |
| <li><a href="http://www.eclipse.org/legal/copyright.php">Copyright Agent</a></li> |
| <li><a href="http://www.eclipse.org/legal/">Legal</a></li> |
| </ul> |
| </div> |
| <div style="clear: both; height: 0; overflow: hidden;"></div> |
| </div> |
| |
| <!-- ************* UI Scripts ************* --> |
| <script type="text/javascript" src="scripts/back-to-top.js"></script> |
| |
| <script type="text/javascript" src="scripts/treeview.js"></script> |
| <script type="text/javascript" src="scripts/toc.js"></script> |
| |
| <!-- ************* Prism.js Syntax Highlighting ************* --> |
| <script src="scripts/prism.js"></script> |
| |
| <script type="text/javascript"> |
| // Add the 'toclist' id for search function |
| $(".toc2 > ul").attr('id', 'toclist'); |
| // Generate a Search input form |
| $("#toclist > li:first-of-type").before('<input type="text" id="pagesearch" onkeyup="search()" placeholder="Search for section...">'); |
| $("#toclist > li:first-of-type").before('<i id="clear" class="fa fa-times-circle-o"></i>'); |
| $("#clear").click(function(){ |
| $("#pagesearch").val(''); |
| search(); |
| $('.toc2 > ul').treeView('collapseAll'); |
| }); |
| // intialize Treeview.js |
| $(".toc2 > ul").treeView(); |
| // Initialize Scrollspy |
| </script> |
| <!-- ************* docinfo-footer *************************************************************** --> |
| </body> |
| </html> |