rendered paste body
element foo implements JavascriptConstructor {
public function js() {
return jsprintf('new FooController(%d, %d)', 1, 2);
}
protected function render() {
$root = <div />;
onloadRegister('%O.init(%O)', $this, $root);
return $root;
}
}
$foo = <foo />;
onloadRegister('GiveMeAFoo(%O)', $foo);
echo $foo;
---
JSCC={
ctors: [function() {
return new FooController(1, 2);
}],
refs: {},
get: function(key) {
if (refs[key]) {
return refs[key];
} else {
refs[key] = ctors[key]();
delete ctors[key];
return refs[key];
}
}
}
<script>GiveMeAFoo(JSCC.get(1))</script>
<div id="randomid" />
<script>JSCC.get(1).init($('randomid'))</script>