我的理解:我认为prop就像是一个黑客,他可以对操作进行拦截,对数据进行篡改,绝对的处理数据的神器
先来一段代码

<html>
	<head>
		<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
	</head>
	<body>

		<input type="text" placeholder="请填写姓名"/>
		<button onclick="submitForm()">提交</button>
		<script>
			let logHandler = {
				get: function (target,key) {
					console.log(`${key}被读取`)
					return target[key]
				},
				set: function (target,key,val) {
					console.log(`${key} 被设置为 ${val}`);
					target[key] = val;
				}
			}
			function submitForm	() {
				let obj = {
					name: $('input').val()
				}
				let targetWithLog = new Proxy(obj, logHandler);
				console.log(targetWithLog.name)
				targetWithLog.name = '杨涛'
				console.log(obj.name)
				console.log('ppppppppppppppppppppppppppppppppppppppppp')
			}	
		</script>
	</body>
</html>

ES6 之 proxy

体会一下,表单提交及数据处理特别合适,其他的还在研究中

相关文章:

  • 2019-03-05
  • 2021-03-31
  • 2021-06-02
  • 2021-12-02
  • 2021-12-17
  • 2018-01-26
  • 2019-09-01
  • 2021-12-12
猜你喜欢
  • 2019-05-31
  • 2021-06-25
  • 2021-06-22
  • 2019-12-11
  • 2019-08-15
  • 2018-09-21
  • 2019-12-31
相关资源
相似解决方案