Posts

Showing posts with the label JavaScript

My first Javascript app

Last night I tried to make a small app/script in javascript (gjs) and it actually worked. :) Here is the code: const GLib = imports.gi.GLib; const GUPnP = imports.gi.GUPnP; const Mainloop = imports.mainloop; // This doesn't start any threads GLib.thread_init (null); let context = new GUPnP.Context ({ main_context: null, host_ip: null, port: 0 }); let cp = new GUPnP.ControlPoint ({ client: context, target: "ssdp:all" }); function onDeviceProxyAvailable (cp, proxy) { log (proxy.get_friendly_name ()); } // Tell us when there is a new device available cp.connect ("device-proxy-available", onDeviceProxyAvailable); // Search and listen for UPnP resources on the network cp.set_active (true); Mainloop.run ("0");

Regarding closures

After reading/watching Stuart's nice slides on Closures in the context of JavaScript, I have started to like JavaScript. Personally, I don't accept any language as a high-level scripting language if it doesn't support closures. Python is therefore straight out of my window. Although Vala isn't a scripting language, it would be nice to have such support in there as well. It already supports lambda functions with no restrictions and Jürg has concrete plans to support closures, it's more a matter of when rather than why or how. When that support is there, just try and stop me from loving Vala. :) UPDATE : Thanks to Anonymous, I now stand corrected that Python does fully support closures. Although I still don't like the fact that it restricts lambda functions to be one-liner but at least it's not straight out of the window anymore. :) UPDATE#2 : Andy Wingo informs me that python doesn't really fully support closures. He even put up a small code fragment to