Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit abb17cc

Browse files
committed
perf(jqLite): optimize off()
'for in' is much faster than Object.keys() and since the events object is ours, we know that we don't need to worry about prototypically inherited properties so we can skip expensive hasOwnProperty check. http://jsperf.com/for-in-vs-object-keys2
1 parent 3e0a2e1 commit abb17cc

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

src/jqLite.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -270,16 +270,11 @@ function jqLiteOff(element, type, fn, unsupported) {
270270
var expandoStore = jqLiteExpandoStore(element);
271271
var events = expandoStore && expandoStore.events;
272272
var handle = expandoStore && expandoStore.handle;
273-
var i;
274-
var types;
275273

276274
if (!handle) return; //no listeners registered
277275

278-
if (isUndefined(type)) {
279-
types = Object.keys(events);
280-
i = types.length;
281-
while (i--) {
282-
type = types[i];
276+
if (!type) {
277+
for (type in events) {
283278
if (type !== '$destroy') {
284279
removeEventListenerFn(element, type, events[type]);
285280
}

0 commit comments

Comments
 (0)