jquery.suggestions: Use Object.create( null )
authorFomafix <fomafix@googlemail.com>
Wed, 29 May 2019 22:56:46 +0000 (00:56 +0200)
committerKrinkle <krinklemail@gmail.com>
Mon, 10 Jun 2019 13:25:04 +0000 (13:25 +0000)
Object.create( null ) creates an Object without predefined methods like
hasOwnProperty or constructor. This allow to use
key in object
instead of
Object.prototype.hasOwnProperty.call( object, key )
even if the key is 'constructor'.

Change-Id: I6ef9019309022a2a990deda685ba71ca61b86df3

resources/src/jquery/jquery.suggestions.js

index 4a1d637..9c7573d 100644 (file)
@@ -90,8 +90,6 @@
 
 ( function () {
 
-       var hasOwn = Object.hasOwnProperty;
-
        /**
         * Cancel any delayed maybeFetch() call and callback the context so
         * they can cancel any async fetching if they use AJAX or something.
                        ) {
                                context.data.prevText = val;
                                // Try cache first
-                               if ( context.config.cache && hasOwn.call( cache, val ) ) {
+                               if ( context.config.cache && val in cache ) {
                                        if ( mw.now() - cache[ val ].timestamp < context.config.cacheMaxAge ) {
                                                context.data.$textbox.suggestions( 'suggestions', cache[ val ].suggestions );
                                                if ( typeof context.config.update.after === 'function' ) {
                                        prevText: null,
 
                                        // Cache of fetched suggestions
-                                       cache: {},
+                                       cache: Object.create( null ),
 
                                        // Number of results visible without scrolling
                                        visibleResults: 0,