属性访问器兼容IE,使用VBScript
<script type="text/javascript">
if(!Object.defineProperty){
try {
execScript(['document.write("This is my first VBScript!")'].join('\n'), 'VBScript');
} catch (e){
console.log('error');
}
} else {
var obj = {};
try {
Object.defineProperty(obj, 'name', {
get: function(){
return "your name is admin";
},
set: function(value){
console.log('new value is ' + value);
}
});
obj.name = 'lisi';
console.log(obj.name);
} catch (e){
console.log(e);
console.log('error');
}
}
</script>