属性访问器兼容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>
posted @ 2020-04-09 10:17  fight139  阅读(240)  评论(0编辑  收藏  举报