回答編集履歴

2

Object.defineProperty(QueryAll.prototype のコードの最適化

2015/10/27 09:13

投稿

think49
think49

スコア18162

test CHANGED
@@ -122,15 +122,7 @@
122
122
 
123
123
  configurable: true,
124
124
 
125
- value: (function (_forEach) {
126
-
127
- return function forEach () {
128
-
129
- return _forEach.apply(this, arguments);
130
-
131
- };
132
-
133
- }(Array.prototype.forEach))
125
+ value: Array.prototype.forEach
134
126
 
135
127
  });
136
128
 

1

無駄な空行削除。Query.prototype.forEach のスコープチェーン上に querySelectorAll, doc が存在した不具合解消

2015/10/27 09:13

投稿

think49
think49

スコア18162

test CHANGED
@@ -21,8 +21,6 @@
21
21
  var forEach = (function (_forEach, slice) {
22
22
 
23
23
  return function forEach (thisArg) {
24
-
25
-
26
24
 
27
25
  return _forEach.apply(thisArg, slice.call(arguments, 1));
28
26
 
@@ -55,6 +53,8 @@
55
53
  }(document.querySelector, document));
56
54
 
57
55
 
56
+
57
+ console.log(query('p'));
58
58
 
59
59
  forEach(queryAll('div'), function (element) {
60
60
 
@@ -108,31 +108,31 @@
108
108
 
109
109
 
110
110
 
111
- Object.defineProperty(QueryAll.prototype, 'forEach', {
111
+ return QueryAll;
112
112
 
113
- writable: true,
114
-
115
- enumerable: false,
116
-
117
- configurable: true,
118
-
119
- value: (function (_forEach) {
120
-
121
- return function forEach () {
122
-
123
- return _forEach.apply(this, arguments);
113
+ }(document.querySelectorAll, document));
124
-
125
- };
126
-
127
- }(Array.prototype.forEach))
128
-
129
- });
130
114
 
131
115
 
132
116
 
133
- return QueryAll;
117
+ Object.defineProperty(QueryAll.prototype, 'forEach', {
134
118
 
119
+ writable: true,
120
+
121
+ enumerable: false,
122
+
123
+ configurable: true,
124
+
125
+ value: (function (_forEach) {
126
+
127
+ return function forEach () {
128
+
135
- }(document.querySelectorAll, document));
129
+ return _forEach.apply(this, arguments);
130
+
131
+ };
132
+
133
+ }(Array.prototype.forEach))
134
+
135
+ });
136
136
 
137
137
 
138
138
 
@@ -191,3 +191,5 @@
191
191
 
192
192
 
193
193
  - [小飼弾 404 Title Not Found - #1 プログラマーの三大美徳その1「怠慢」ITpro](http://itpro.nikkeibp.co.jp/article/Watcher/20061005/250057/)
194
+
195
+