new
| 1 | const People = function(name) { | 
双向绑定
查看效果:地址1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31var input = document.getElementById('input')
var show = document.getElementById('show')
input.addEventListener('input', function(e) {
	obj.text = e.target.value
})
// defineProperty 实现
var obj = {}
Object.defineProperty(obj, 'text', {
  configurable: true,
  enumerable: true,
  get: function() {
    return obj.text
  },
  set: function(newValue) {
    input.value = newValue
    show.innerText = newValue
  }
})
// proxy 实现
var obj = new Proxy({}, {  
  get: function(obj, prop) {
    return obj[prop]
  },
  set: function(obj, prop, newValue) {
    obj[prop] = newValue
    input.value = newValue
    show.innerText = newValue
  }
})
call
| 1 | Function.prototype.call = function(context, ...args) { | 
apply
| 1 | Function.prototype.apply = function(context, args) { | 
bind
| 1 | Function.prototype.bind = function(context, args) { |