Javascript `this' equivalent in Biwascheme?

50 views
Skip to first unread message

Neprilagodjen Zg

unread,
Jul 8, 2015, 6:21:17 AM7/8/15
to biwas...@googlegroups.com

I have a question about javascript `this' keyword equivalent in biwascheme.

For example, in the following code snippet, the variable `this' is used to access and animate all img elements in:

$("#album-list img").mouseover(function () {
    $(this).animate({ height: '+=25', width: '+=25' });
});

I'm wondering how to write the equivalent code in biwascheme - the problem is, of course, that biwascheme, as far as I know, lacks the variable `this'. Any suggestions?

jcubic

unread,
Jul 12, 2016, 5:51:55 PM7/12/16
to BiwaScheme
You can define scheme function in javascript and define `this` variable inside like this:

BiwaScheme.define_libfunc(".each", 2, 2, function(args) {
    var intp = new BiwaScheme.Interpreter();
    return $(args[0]).each(function(idx, elem) {
        BiwaScheme.CoreEnv['this'] = this;
        intp.invoke_closure(args[1], [$(elem)]);
    });
});

then you can call this function using this scheme code:

(.each ($ "p") (lambda () (.css ($ this) "color" "red")))

You can find basic jQuery in biwascheme here http://terminal.jcubic.pl/js/jqbiwa.js

In above code the this will remember last executed function for better this you will need to save window in CoreEnv['this'] after each function like:

BiwaScheme.define_libfunc(".each", 2, 2, function(args) {
    var intp = new BiwaScheme.Interpreter();
    var ret = $(args[0]).each(function(idx, elem) {
        BiwaScheme.CoreEnv['this'] = this;
        intp.invoke_closure(args[1], [$(elem)]);
    });
    BiwaScheme.CoreEnv['this'] = window;
    return ret;
});
Reply all
Reply to author
Forward
0 new messages