Focus on Nativescript for some time, said the first beta version of March, finally released.
//declare the extended nativescriptactivity functionalityvarExtendsobject ={onCreate:function(savedstate) {//Call the base Nativescriptactivity.oncreate method //the ' this ' variable points to a nativescriptactivity instance This. Super.oncreate (savedstate); //Create a button and set it as the main content varbutton =NewAndroid.widget.Button ( This); Button.settext ("Hello World"); This. Setcontentview (button); }}//Pass the extends object to create a new nativescriptactivity instancevarMainactivity =com.tns.NativeScriptActivity.extends (extendsobject);varApplicationinitobject ={getactivity:function(Intent) {//This method is called whenever a new instance of Nativescriptactivity are about to be created returnmainactivity; }, OnCreate:function() { //This is the first method called. Called from the Android.app.Application.onCreate method. } }//The Nativescriptruntime exposes the App object within the global contextApp.init (Applicationinitobject);
Like the code above, using JavaScript to build an Android activity, is not cool!
Of course it's also possible to write iOS native apps, which is not the coolest and even cooler, it also provides a set of "public" APIs, and a set of UI control libraries that can be described in XML, so you can define the interface and generate corresponding local controls on different platforms.
<Pagexmlns= "Http://www.nativescript.org/tns.xsd"Loaded= "pageLoaded"> <Stacklayout> <Labeltext= "Tap the button"CssClass= "title"/> <Buttontext= "Tap"Tap= "{{tapaction}}" /> <Labeltext= "{{message}}"CssClass= "message"TextWrap= "true"/> <Buttontext= "Test Button"/> </Stacklayout></Page>
It also supports "data binding", which you believe?!
Example of the sample:
Using JavaScript to write Android and iOS naitve apps is really cool.