var cache = {};
var _gen = function(name)
{
if(cache.hasOwnProperty(name))
return cache[name];
// ...
| var a = new MutableValue( | |
| { | |
| __call__: function(b) | |
| { | |
| this = b; | |
| }; | |
| } | |
| ); | |
| a(1); // really a = 1 |
| (function($G) | |
| { | |
| var _extend = | |
| Object.getOwnPropertyNames && function(from, to) | |
| { | |
| var keys = Object.getOwnPropertyNames(from); | |
| var i = keys.length; while(i--) | |
| { | |
| var key = keys[i]; |
| (function($G) | |
| { | |
| var OldRegExp = $G.RegExp; | |
| var _createHashTable = | |
| Object.create && function() | |
| { | |
| return Object.create(null); | |
| } || | |
| {}.__proto__ && function() |
| /* | |
| # Deflate compression using Canvas 2d API | |
| Canvas API provides HTMLCanvasElement#toDataURL, which allows serialize canvas image to png image. I do not know about result png format (how many bits per pixel and there is alpha channel or not, may be palette or grayscale image). WHATWG spec also do not points this ie its UA dependent. Anyway basic rules: | |
| + browsers do not supports images with width or height > 20 000 px => we use square image instead linear(1*X or X*1) | |
| + if alpha component of canvas data eq 0 => browser reset red, green, blue to 0 too even if globalCompositeOperation = 'copy' | |
| + even if globalCompositeOperation = 'copy', globalAlpha = 1.0, dest alpha of pixel eq 255 - browser blends src image data when you perform putImageData and original red, green, blue components corrupts due floating point errors. For example we have one pixel [1,129,130,131], let see putImageData(this pixel); getImageData() -> [1,128,130,131]; drawImage(toDataUrl()); ; getImageData -> [1,126,128,131] => |
| var a = [x*2 for each (x in [1,2,3])]; | |
| var a = [1,2,3].map(_("x -> 2*x")); | |
| var b = [x*2 for each (x in [1,2,3]) if (x>1)]; | |
| var a = [1,2,3].filter(_("x -> x > 1")).map(_("x -> 2*x")); | |
| var c = [x+y | |
| for each (x in [1,2,3]) | |
| for each (y in [10,20,30]) | |
| if (x>1) |
| // from https://gist.github.com/613924 | |
| Proxy._noopHandler = function noopHandler(obj) { | |
| return { | |
| getOwnPropertyDescriptor: function(name) { | |
| var desc = Object.getOwnPropertyDescriptor(obj, name); | |
| // a trapping proxy's properties must always be configurable | |
| desc.configurable = true; | |
| return desc; | |
| }, | |
| getPropertyDescriptor: function(name) { |
| /* | |
| unfortunately you can not debug it :( | |
| */ | |
| (function($G) | |
| { | |
| $G._import = function(_fn, modules) | |
| { | |
| var argsString = ''; | |
| var args = []; |
| /* | |
| Shows that Mutexes, Events, and Critical Sections are available in js "threading" model too. :) | |
| WaitForSingleObject http://msdn.microsoft.com/en-us/library/ms687032(VS.85).aspx | |
| WaitForMultipleObjects http://msdn.microsoft.com/en-us/library/ms687025(VS.85).aspx | |
| Event http://msdn.microsoft.com/en-us/library/ms682396(VS.85).aspx | |
| */ | |
| (function($G) | |
| { |
| /* | |
| my OOP in js is more and more closer to java/c++/c# :P | |
| 1) now it allows create instance w/o <new> keyword (all native classes supports instance creating w/o <new> except <Date>) | |
| 2) removes <prototype> extra word when you access to static fields and methods(<Class.prototype = Class> magic) | |
| 3) automatic delegates/<Function#bind>. My delegates always is begined from '_on' prefix | |
| 4) has own implementation of <instanceof> operator - <Object#_hasBaseClass> | |
| 5) base constructors call via special <Object#_callBaseConstructor> | |
| 6) derivation do not uses prototype machanism(because slow resolving). I use just copy _methods/InternalTypes/CONSTS. Yes its based on codestyle. But you can use <typeof> or <Object#toString> instead. | |
| */ |