Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Crazy IE getter setter proxy hack
<!-- modified from -->
<title>A Crazy Getter/Setter Hack</title>
<script language="VBScript" type="text/VBScript">
Function exec_vb_global(code)
End Function
<script type="text/javascript">
// Create the main default thing object, we will proxy this later
function ThingBase() {
// Private
var space = 'something about the awesome';
this.getSpace = function() {
return space;
this.setSpace = function(value) {
space = value;
this.groove = function() {
alert('nn ts nn ts nn ts nn ts');
// We need a factory to build this becuase we can't call 'new' from vbscript
function ThingBaseFactory() {
return new ThingBase();
// Eventually this text construction will be automated for the proxy
// All you need to do is build the proxy for each property set*, get*
// and stub each method
var obj = ""+
"Class ThingProxy\n"+
" Private obj__\n"+
" Public Property Get space\n"+
" space = obj__.getSpace()\n"+
" End Property\n"+
" Public Property Let space(value)\n"+
" obj__.setSpace(value)\n"+
" End Property\n"+
" Public Function groove\n"+
" obj__.groove()\n"+
" End Function\n"+
" Private Sub Class_Initialize()\n"+
" Set obj__ = ThingBaseFactory()\n"+
" End Sub\n"+
"End Class\n"+
"' We need a factory because we can't call 'New' from javascript\n"+
"Function thingProxyFactory()\n"+
" Dim tmp\n"+
" Set tmp = New ThingProxy\n"+
" Set thingProxyFactory = tmp\n"+
"End Function\n";
// Register the proxy class in the global context, make the factory global
// The actual thing constructor
var Thing = function() { return (window["thingProxyFactory"]()) }
// Use the thing
var t = new Thing();
alert(; = "Imma let you finish";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment