Refactor: Replace jQuery utilities with ES6+ alternatives#679
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the multiple-select plugin to reduce reliance on jQuery utility helpers by introducing a native extend() utility and replacing $.each / $.inArray usage with ES6+ equivalents.
Changes:
- Added
extend()(and internal plain-object detection) tosrc/utils/index.jsand exported it for reuse. - Replaced
$.extend()usages withextend()in core initialization and option-handling paths. - Replaced
$.each()loops withfor...ofiteration and replaced$.inArray()checks withArray.prototype.includes().
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/utils/index.js | Introduces and exports a native extend() implementation to replace $.extend(). |
| src/multiple-select.js | Updates plugin entrypoint to use extend() and includes() for method validation. |
| src/MultipleSelect.js | Updates core class to use extend() and replaces $.each() loops with for...of. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
8bf5513 to
7401e4f
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
7401e4f to
ef3018a
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 7 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This PR refactors the codebase to replace jQuery utility methods with modern ES6+ alternatives, making the code more idiomatic and maintainable. Changes: - Replace $.extend() with native extend() function * Uses proven implementation from bootstrap-table * Supports both shallow and deep merging * Maintains full jQuery API compatibility - Replace $.each() with native for...of loops * More idiomatic ES6+ syntax * Better performance and readability - Replace $.inArray() with Array.prototype.includes() * Simpler and more intuitive API - Add extend() and isObject() utilities to src/utils/index.js * No separate compatibility layer needed * Consistent with existing code style Benefits: - More native JavaScript, less jQuery dependency - Better performance with native methods - Future-proof for jQuery 4.0+ - Cleaner, more maintainable code All tests pass and lint checks are clean.
ef3018a to
bb0196a
Compare
🤔 Type of Request
📝 Description
This PR refactors the codebase to replace jQuery utility methods with modern ES6+ alternatives. The code is now more idiomatic and aligns with modern JavaScript best practices.
🎯 Changes
1. Replace
$.extend()with nativeextend()extend({}, obj1, obj2)extend(true, {}, obj)2. Replace
$.each()with nativefor...of$.each(collection, (i, elm) => { ... })for (const [i, elm] of Array.from(collection).entries()) { ... }3. Replace
$.inArray()with nativeArray.prototype.includes()if ($.inArray(option, Constants.METHODS) < 0)if (!Constants.METHODS.includes(option))📁 Files Modified
src/MultipleSelect.js- Updated to useextend()andfor...ofsrc/multiple-select.js- Updated to useextend()andincludes()src/utils/index.js- Addedextend()andisObject()utilities✨ Benefits
includes()is more intuitive thaninArray()✅ Testing
All existing functionality is preserved. No breaking changes for end users.
🔍 Code Examples
Love multiple-select? Please consider supporting us:
👉 https://opencollective.com/multiple-select/donate