Delegates in JavaScript. Now with parameters.

August 28, 2006

Filed under: Philosophy,Script — Andrew @ 10:45 am

Here is an extended delegate function:

  function delegate( that, thatMethod )
    if(arguments.length > 2)
      var _params = []; 
      for(var n = 2; n < arguments.length; ++n) _params.push(arguments[n]);
      return function() { return thatMethod.apply(that,_params); }
      return function() { return; }

And here is an example. Note that obj.method now accepts additional parameter p

  var obj =
    name: "someName",
    method: function (p ) { alert( + ":" + p );  }

  function testIt()
    window.setTimeout( delegate( obj, obj.method, "parameter!" ), 1000 );

Example of the delegate is delegate-test.

Note: this is so called parametrized delegate - parameters defined at the point of construction of the delegate - in delegate() call per se.

If you need delegate that will be inoked with parameters supplied by the caller you should use this one:

  function delegate_cp( that, thatMethod )
      return function() { return thatMethod.apply(that,arguments); }

So caller will call it as:

  var d1 = delegate_cp( obj, obj.method );
  d1( param1, param2 ); /* parameters for the delegate
           call provided at the point of invocation. */

Java GUI executable without JRE… Are you kidding me?

August 19, 2006

Filed under: Philosophy — Andrew @ 10:55 pm

Three years ago (or so) I did experimental project named J-SMILE to prove that it is possible.

Main idea of it is simple – to create as small as possible Java (Virtual Machine) that can be attached to compiled Java bytecode (.class files).

Physically J-SMILE VM is an .exe file of size 200k. These 200k include:

  • Waba VM extended to support Java 1.2 language specification pretty much in full – green threads, copying GC, float support.

  • Set of native GUI functions (Graphics, Font, Window, etc).

  • Special class loader capable to load class files from trailer – .class files packaged and attached to the end of the exe file of J-SMILE VM.

I have designed mini set of GUI primitives (Widgets) like listbox, editbox, etc. and created this simple demo application:

This demo application is about 400k = 200k of J-SMILE VM + all classes needed to run it ( mini version of java.lang.* and smile.* ). Source code of class files used in this application is here.

No JRE/VM version checks, no installation step needed, self-sufficient… Cool, eh?

And now goes the question: why all Java GUI solutions so monstrous and heavy?
Premature Generalization, eh? Got Deja Vu reading excellent Eric Gunnerson’s C# Compendium.

Phrase that made my day.

August 18, 2006

Filed under: Philosophy — Andrew @ 2:10 pm

“… people knew how to write small, efficient programs in those days, a skill that has subsequently been lost.”

© Tanenbaum (?)

Delegates in JavaScript

August 16, 2006

Filed under: Sciter,Script — Andrew @ 10:35 am

Simple definition:

  • delegate is a value – reference to the pair of object and its method. Lets name them as delegate.object and delegate.method.

  • delegate invocation is a way of calling of delegate.method in context of delegate.object. So inside code of the delegate.method variable this points to the delegate.object.

To be practically useful delegate in JavaScript must be implemented as a reference to function so, for example, we can say:

window.setTimeout( delegate( obj, obj.method ), 1000 );

and obj.method will be invoked one second later with this referring to the obj.

Here is probably simplest possible implementation of such delegate function in JavaScript (and in TIScript):

function delegate( that, thatMethod )
return function() { return; }

It returns reference to the function-thunk ( delegate per se ). This function-thunk being called will invoke thatMethod in context of that object. This implementation employs the fact that namespace of inner function in JS includes namespace of outer function.

Technically this means following: call frames in JS are also (GC-able) objects and body of the function (callee) has access to the frame of caller.

H-SMILE core. Popup and context menus (HTMLayout and Sciter engines)

August 13, 2006

Filed under: HTMLayout,Sciter — Andrew @ 11:56 pm

For references in this article use std-menus.css file.

Popup menus

Popup menus are designed as set of behaviors menu-bar, menu and popup-menu. As always in the engine behaviors are applied to the DOM elements by CSS attribute behavior.

Menus in the engine are ordinary DOM elements thus can be styled in full by using CSS declarations. The behaviors handle mouse and keyboard events allowing to do navigation through menu items. Content of menus is not limited by only menu items – you can use any reasonable markup inside including input elements. By using input elements it is possible to implement lightweight property sheets by using engine. See Context Menus section.


Sciter. Part V. Platforms

Filed under: Sciter — Andrew @ 12:40 am

Platforms supported and planned to be supported by Sciter:

  1. Currently – all incarnations of Windows (starting from Win98 SE and Win NT4). Desktop and Mobile.

  2. Planned – all incarnations of X-Windows. Desktop and Mobile.

  3. Planned – Mac OSX.

No plans to support current versions of Symbian OS and Palm OS

Next Page »