📜 ⬆️ ⬇️

Getters & Setters in IE5 +

This is what inspired habrahabr.ru/blogs/javascript/66242

Contrary to popular opinion, IE still knows how to assign accessors, though only in VB, which is enough for some tasks.

<script language= "vbscript" >
' ,
Class Accessor
Public Property Let hook(val) ' hook Accessor
MsgBox val
End Property
End Class

Dim access ' VB
Set access = New Accessor ' Accessor
</script>

<script language= "jscript" >
// .. VB JS , access
access.hook = 'ololo' ;
</script>


* This source code was highlighted with Source Code Highlighter .

')
In other words, there are accessors in VB, VB is in all IE and the VB and JS namespace is common, it can be used.

For my task, this wrapper was enough:

<script>
// VB, language IE VB
</script>

<script language= "vbscript" >
Class Accessor
Public Property Let hook(val)
propset val ' hook propset
End Property
End Class
Dim access
Set access = New Accessor
</script>


<script>
function propset(val) { //
alert(val);
}
if ( /*@cc_on!@*/ true ) { // Accessor javascript
access = {};
access.__defineSetter__( 'hook' , function (val) {propset(val)})
}

access.hook = 'hi' ; //
</script>


* This source code was highlighted with Source Code Highlighter .


Unfortunately, not without a spoon of tar, the values ​​assigned can only be scalar, any objects will lead to an error:

access.hook = {}; // :

* This source code was highlighted with Source Code Highlighter .


In general, not a connoisseur of VB and the subtleties of its implementation, perhaps this problem can somehow be circumvented?

UPD: Assigned values ​​can be not only scalar, thanks keksn , for this Accessor should be declared as follows:
Class Accessor
Public Property Let hook(val)
propset val
End Property
Public Property Set hook(val)
propset val
End Property
End Class
Dim access
Set access = New Accessor


* This source code was highlighted with Source Code Highlighter .

Source: https://habr.com/ru/post/75158/


All Articles