JavaScript For Native Apps
Written by Ian Elliot   
Tuesday, 10 March 2015

NativeScript is a system that allows you to write native apps for Android, iOS and Windows Phone using JavaScript - and no this isn't a wrapper for an HTML app.

You may have encountered frameworks like PhoneGap/Cordova that enable you to run Web apps as if they were native apps, but NativeScript follows Microsoft's approach - you can use different languages and even markup to create true native apps. At the moment Android is mainly Java and iOS is mainly Objective C/Swift. 




NativeScript is standard JavaScript that has been extended with some clever middleware that allows you to call functions in the native API.

This sounds complicated, but it actually fairly straightforward. You make a full reference to the native API function, for example 

var file=new;

and this sets up a call to the Java API function File.

The clever part is that the JavaScript string that specifies the path is automatically converted to a java.lang.String object for the call. The Java File object as attached to the JavaScript variable file in the sense that any attempt to access properties on file are passed on to the Java File object. That is, file acts as a proxy for File. 

The JavaScript is interpreted using the standard JavaScript engine V8 for Android and webkit for iOS and Windows Phone.  Notice, however, that no wrapper is used - there is no browser component building the UI for you from HTML. If you want a button then you have to write JavaScript that calls the native class constructor.

At this point you may start to think that this is great but wait - I still have to write three versions of my app. One using Android native calls, one using iOS native calls and one using Windows Phone native calls. This means your only advantage is that you can make use of JavaScript for all three and this is possibly a language you know. The advantage of using a wrapper is that you are essentially writing a web app, i.e something that could run in a browser, and then using a wrapper that is essentially a modified browser to make it look a bit like a native app. 




NativeScript can help you write just one app for all three platforms using a set of abstractions by way of the NativeScript Modules layer that map onto the native APIs. So instead of specifically calling the API function for File you can simply write:

var file=File(path);

and the abstraction layer will map the JavaScript to the correct native call.

The danger with adopting any scheme like the NativeScript Modules is that making any such abstractions complete is difficult and this means that there are always things you cannot do. In the case of NativeScript this isn't such a worry because you can always fall back on direct API calls.



The NativeScript system is built on Node.js and to use it you still need to install parts of the native system you are working with - XCode, for example. So you still need some skill in using the native SDKs.

You might also be worried about the overheads in using all of these translations between systems, but it is clamed that it only slows things down by about 10%. 

NativeScript has been developed by Telerik, known for its wrapper approach to developing "native" apps with JavaScript. The surprise is that NativeScript is open source under the Apache 2.0 licence. Presumably Telerik hopes to make a profit on supplying extras such as Telerik Platform Services

If this can be made to work, and if the performance loss is only about 10% as claimed, then this is a useful alternative way of creating native apps. It is hoped that a Version 1 will ship in April. 




Inaugural STOC Test Of Time Awards

At the 2021 ACM Symposium on Theory of Computing (STOC), held online in June, sixteen recipients were honored in respect of seven papers presented at past STOC conferences  which have had a long- [ ... ]

RoboTaxi - A Safe Ride Through An Unruly Landscape

We have grown used to seeing self-driving cars cruising around California suburbs, making all the correct moves at traffic intersections. Now see what happens when you switch the scene to a Chinese ur [ ... ]

More News






or email your comment to:

Last Updated ( Wednesday, 06 May 2015 )