I wasn’t gonna blog this because I couldn’t be bothered but Mario asked me if I had it documented anywhere and I guess it’s nice to have it somewhere. So I was looking to create setters in legacy browsers like IE7 and it would be nice to use them on custom objects in IE8. I came up with the following VBS hack:-
execScript("Class cnProperty Let x(y)nalert(y)nEnd PropertynEnd ClassnSet obj=new c","VBScript");obj.x=1;//yeah js calls vbs
Pretty cool calling VBS from JS then using a VBS object inside JS
Ok and now some constant stuff I tweeted before but I quite like so I’ll post here too. Constants are weird in JavaScript, when you think about them you think in a value that cannot change but when it comes to objects they can’t be constants for some reason. I dunno why they could be implemented quite easily by creating a Getter only object but anyway:-
//example1
const x={};x.y=123;alert(x.y)//Objects aren't constants!
//example2 (need to run separately of course
const x={};x.toString=x.valueOf=function() { return 1; };alert(x)
Finally I’ll leave you with a quiz, what is “x” equal to without running?:-
var x=1; function y() { x=3; alert(x); return; const x=2;}y()// x == ?