Browse Source

cached $bind results (fixed issue #1349)

Nicolas Cannasse 12 years ago
parent
commit
2d52cbed3a
2 changed files with 3 additions and 3 deletions
  1. 2 2
      genjs.ml
  2. 1 1
      std/js/_std/Reflect.hx

+ 2 - 2
genjs.ml

@@ -1171,9 +1171,9 @@ let generate com =
 		newline ctx;
 	end;
 	if has_feature ctx "use.$bind" then begin
-		print ctx "var $_";
+		print ctx "var $_, $fid = 0";
 		newline ctx;
-		print ctx "function $bind(o,m) { var f = function(){ return f.method.apply(f.scope, arguments); }; f.scope = o; f.method = m; return f; }";
+		print ctx "function $bind(o,m) { if( m.__id__ == null ) m.__id__ = $fid++; var f; if( o.hx__closures__ == null ) o.hx__closures__ = {}; else f = o.hx__closures__[m.__id__]; if( f == null ) { f = function(){ return f.method.apply(f.scope, arguments); }; f.scope = o; f.method = m; o.hx__closures__[m.__id__] = f; } return f; }";
 		ctx.separator <- true;
 		newline ctx;
 	end;

+ 1 - 1
std/js/_std/Reflect.hx

@@ -57,7 +57,7 @@
 		if (o != null) untyped {
 			var hasOwnProperty = __js__('Object').prototype.hasOwnProperty;
 			__js__("for( var f in o ) {");
-			if( f != "__id__" && hasOwnProperty.call(o, f) ) a.push(f);
+			if( f != "__id__" && f != "hx__closures__" && hasOwnProperty.call(o, f) ) a.push(f);
 			__js__("}");
 		}
 		return a;