回答編集履歴
2
getterもオーバーライドしないといけなかったので修正
answer
CHANGED
@@ -22,14 +22,13 @@
|
|
22
22
|
|
23
23
|
### ダミー要素なしでも行けました
|
24
24
|
が、互換性は確認してないです。
|
25
|
-
[https://jsfiddle.net/bmvcneoo/
|
25
|
+
[https://jsfiddle.net/bmvcneoo/2/](https://jsfiddle.net/bmvcneoo/2/)
|
26
26
|
```javascript
|
27
27
|
(function(target){
|
28
28
|
Object.defineProperty(target, 'value',{
|
29
|
-
get : function(){return value
|
29
|
+
get : function(){return Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,'value').get.call(target)},
|
30
30
|
set : function(x){
|
31
31
|
if (x) {console.log(x)}
|
32
|
-
value = x;
|
33
32
|
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,'value').set.call(target,x);
|
34
33
|
}
|
35
34
|
})
|
1
ダミー要素なしでも行けました
answer
CHANGED
@@ -17,4 +17,21 @@
|
|
17
17
|
set : function(x){ if (x) { console.log(x) } value = x; }
|
18
18
|
})
|
19
19
|
})(document.querySelector('.p-region[type=hidden]'))
|
20
|
+
```
|
21
|
+
|
22
|
+
|
23
|
+
### ダミー要素なしでも行けました
|
24
|
+
が、互換性は確認してないです。
|
25
|
+
[https://jsfiddle.net/bmvcneoo/1/](https://jsfiddle.net/bmvcneoo/1/)
|
26
|
+
```javascript
|
27
|
+
(function(target){
|
28
|
+
Object.defineProperty(target, 'value',{
|
29
|
+
get : function(){return value;},
|
30
|
+
set : function(x){
|
31
|
+
if (x) {console.log(x)}
|
32
|
+
value = x;
|
33
|
+
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,'value').set.call(target,x);
|
34
|
+
}
|
35
|
+
})
|
36
|
+
})(document.querySelector('.p-region'))
|
20
37
|
```
|