JAVA Script

Call, Bind and Apply Methods

Bind( )

The bind method creates a new function and sets the this keyword to the specified object.

Syntax:

function.bind(thisArg, optionalArguments)

Call ( )

The call method sets the this inside the function and immediately executes that function.

The difference between call() and bind() is that the call() sets the this keyword and executes the function immediately and it does not create a new copy of the function, while the bind() creates a copy of that function and sets the this keyword.

Syntax:

function.call(thisArg, arg1, agr2, ...)

Apply ( )

The apply() method is similar to call(). The difference is that the apply() method accepts an array of arguments instead of comma separated values.

Syntax:

function.apply(thisArg, [argumentsArr])

 

 

JavaScript Use Strict

 "use strict"; Defines that JavaScript code should be executed in "strict mode".
 
 The "use strict" directive was new in ECMAScript version 5.

It is not a statement, but a literal expression, ignored by earlier versions of JavaScript.

The purpose of "use strict" is to indicate that the code should be executed in "strict mode".

All modern browsers support "use strict" except Internet Explorer 9 and lower:

 

The strict mode in JavaScript does not allow following things:

  1. Use of undefined variables
  2. Use of reserved keywords as variable or function name
  3. Duplicate properties of an object
  4. Duplicate parameters of function
  5. Assign values to read-only properties
  6. Modifying arguments object
  7. Octal numeric literals
  8. with statement
  9. eval function to create a variable
 

Why Strict Mode?

Strict mode makes it easier to write "secure" JavaScript.

Strict mode changes previously accepted "bad syntax" into real errors.

As an example, in normal JavaScript, mistyping a variable name creates a new global variable. In strict mode, this will throw an error, making it impossible to accidentally create a global variable.

In normal JavaScript, a developer will not receive any error feedback assigning values to non-writable properties.

In strict mode, any assignment to a non-writable property, a getter-only property, a non-existing property, a non-existing variable, or a non-existing object, will throw an error.

Keywords reserved for future JavaScript versions can NOT be used as variable names in strict mode.

These are:

  • implements
  • interface
  • let
  • package
  • private
  • protected
  • public
  • static
  • yield
 

  == and ===

What is == in JavaScript?

Double equals (==) is a comparison operator, which transforms the operands having the same type before comparison.

So, when you compare string with a number, JavaScript converts any string to a number. An empty string is always converts to zero. A string with no numeric value is converts to NaN (Not a Number), which returns false.

What is === in JavaScript?

=== (Triple equals) is a strict equality comparison operator in JavaScript, which returns false for the values which are not of a similar type. This operator performs type casting for equality. If we compare 2 with “2” using ===, then it will return a false value.

 
 
 
 
 
 
 
 
 
 
 
 


How to load SAPUI5 files from CDN for performance improvements in Fiori and Standalone UI5 apps (2526542)

 SAP_UI 7.55 (SAP Front-end Server 2020) and greater:

SAPUI5 can either be loaded locally with a relative path from an application server or externally from a Content Delivery Network (CDN).

To access your SAPUI5 libraries from a Content Delivery Network (CDN) instead of your local MIME respository, you need to configure your custom CDN of choice as an external location in the Customizing of your backend system.

For more information, see the documentation for the Customizing activity Configure SAPUI5 Bootstrapping in Customizing under SAP NetWeaver  UI Technologies  SAPUI5.




SAP_UI 7.54 and earlier:

See the following SAP Help documentation or follow the illustrated steps below for loading SAPUI5 files from CDN in the Fiori Launchpad. This functionality is only supported for SAPUI5 versions 1.44 (SAP_UI 751 SP01) and higher.  As this method uses roles for assignment of the functionality, this makes it possible to have some users (e.g., external or test users) load SAPUI5 resources from the CDN while other users (e.g. local and internal only) would load SAPUI5 resources from the NetWeaver Gateway.

SAP Help - SAP Fiori Launchpad - Loading SAPUI5 from a Content Delivery Network (CDN)

*Note that this only impacts the SAPUI5 library files. All requests for Fiori Launchpad and App specific files, and dynamic resources, such as OData requests, will be returned via customer environment.

  1. Open the SAP Fiori Launchpad Designer for the CUST layer (e.g. by using transaction code /ui2/flpd_cust)
  2. Search for the Catalog '/UI2/CONFIG/UI5/CDN'
  3. Go to the Target Mapping configuration
  4. Set following parameter(s):
    • /ui5/cdn/enabled    Default Value  set as   "true" : for enabling CDN resource consumption
    • /ui5/cdn/url            Default Value  set as     e.g.  https://<customer provided CDN host>/1.71.21/resources : for specifying the url of the CDN and the SAPUI5 version to be consumed.
      *Note: for SAP_UI 7.51+, unless using a customer-provided CDN, do not use parameter '/ui5/cdn/url' and check that the SAP Note 2402766 is implemented if for SP01. The version for loading the SAPUI5 library will come from the ABAP frontend server.
      It is always recommended to use the latest SAPUI5 patch.


  5. Go to t-code PFCG and create a custom Role e.g. Z_CDN
  6. Add to this role the '/UI2/CONFIG/UI5/CDN' Fiori Catalog


  7. Assign this role to users which should load SAPUI5 resources via CDN

For standalone UI5 apps, please see step 3 of the following for helpful hints:

SAPUI5 Application Startup Performance - Best Practices



How to test an app with a different SAPUI5 version (2495109)

 With your app running in the browser, open the Technical Information Dialog by pressing CTRL + Alt + Shift + P.





Insert the URL to the required SAPUI5 version on the CDN, as described in the following documentation.

Variant for Bootstrapping from Content Delivery Network



Then press button "Activate Reboot URL". The following popup will appear:




Now refresh the page. A warning will appear indicating that the UI5 is booted from a different source:

 


After accepting the warning, the app will be loaded with the indicated SAPUI5 version. If you refresh again, the app will be loaded again with the original defined UI5 version.



How to set SAPUI5 Application to use different UI5 version than Portal in Cloud Foundry (2924069)

 Symptom

It is required to run custom SAPUI5 applications on a specific SAPUI5 version which is different than the Portal's SAPUI5 version.


Cause

Cloud Portal Service on Cloud Foundry always runs the latest available SAPUI5 version. Certain applications may require a different SAPUI5 version to work properly.

Resolution

Setting the SAP UI5 version for specific applications is not possible. What is possible, is to change the SAPUI5 Version for the whole Cloud Portal Site. This can only be done if you developed your own Launchpad Module.

Follow the below steps to set a specific SAPUI5 version to be used on your custom launchpad module deployed on Cloud Foundry:

  1. Open the Launchpad project on your IDE of choice;
  2. Open the CommonDataModel.json file of the Fiori Launchpad Module;
    The CommonDataModel.json file that is stored in the portal-site folder. See the example from BAS below:


  3. Search for sap.cloud.portal inside the sites entry;
  4. Under config, add "ui5LibraryUrl": "https://sapui5.hana.ondemand.com/<sapui5_version>"
  5. Save the changes;
  6. Build the MTAR;
  7. Deploy the Launchpad Module to Cloud Foundry.

See example below:

"sites": [{
    ...,
    "payload": {
        ...,
        "sap.cloud.portal": {
            "config": {
                "theme.id": "sap_fiori_3",
                "theme.active": ["sap_fiori_3", "sap_belize_hcb", "sap_belize_hcw"],
                "ui5LibraryUrl": "https://sapui5.hana.ondemand.com/1.96.9"
            }
        }
    }
}]

WARNING: If an invalid SAPUI5 version is set, the site will fail to open.

The available SAPUI5 versions can be found on the SAPUI5 versions Maintenance Status page.



one or more constraints have not been satisfied - UI5 Eclipse error

 when all process is done completely on creating a UI5 project using Eclipse you may face the following error.

"one or more constraints have not been satisfied"



Solution for the same is: