This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This library extends standard "Object.create" method | |
* with ability to create object with specified class. | |
* | |
* Also it defines concept of a meta-constructor which | |
* creates other construcotrs, which in turn create | |
* object with specified class. | |
* | |
* Currently, non-standard __proto__ extension | |
* is used to inject the needed prototype for arrays. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This library defines a new style ES objects | |
* which support delegation based mixins. A mixin | |
* chain is stored in the internal [[Mixin]] property. | |
* | |
* Used features: Harmony (ES6) proxies. | |
* | |
* Tested in FF4 beta. | |
* | |
* @author Dmitry A. Soshnikov <[email protected]> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This library defines magic properties and methods | |
* for objects. Generic hooks are: __get__, __set__, | |
* __delete__, __count__, __call__, __construct__, | |
* __noSuchProperty__ and __noSuchMethod__. | |
* | |
* Used features: Harmony (ES6) proxies. | |
* | |
* Tested in FF4 beta. | |
* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Console object for BESEN | |
* @author Dmitry A. Soshnikov <[email protected]> | |
*/ | |
(function initConsole(global) { | |
// helpers | |
var getClass = Object.prototype.toString; | |
var timeMap = {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// lambda lifting (http://en.wikipedia.org/wiki/Lambda_lifting) | |
// in GNU C; use inner functions which are not closures | |
// of course, but have access to free variables | |
// | |
// by Dmitry A. Soshnikov | |
#include <stdio.h> | |
// a pointer to a function type | |
typedef int (*funcPtr)(int); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Lexical and dynamic scopes in Perl; | |
# Static (lexical) scope uses model of | |
# environments with frames; dynamic scope | |
# uses single global var frame. | |
$a = 0; | |
sub foo { | |
return $a; | |
} | |
sub staticScope { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# "Understanding Python's closures". | |
# | |
# Tested in Python 3.1.2 | |
# | |
# General points: | |
# | |
# 1. Closured lexical environments are stored | |
# in the property __closure__ of a function | |
# | |
# 2. If a function does not use free variables |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Short notation for expression funargs - λ | |
* (not for production use, but just for fun, | |
* since closures are not supported -> only | |
* operations on passed argument "x") | |
* | |
* by Dmitry A. Soshnikov | |
*/ | |
function λ(code) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python does not save not used bindings in | |
# the closured environment. However, even | |
# `eval` doesn't help to save them. | |
# | |
# In contrast, ECMAScript having environments | |
# frames, normaly find variable "x", see | |
# the same ES example here: https://gist.github.com/734485 | |
# | |
# by Dmitry A. Soshnikov | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ECMAScript closures all environment frames | |
* (by the spec), so closured "x" variable is | |
* available in the dynamic `eval`. | |
* | |
* This example is made to show the difference | |
* of the Python's closures implementation, | |
* see it here: https://gist.github.com/734482 | |
* | |
* by Dmitry A. Soshnikov |