Skip to content

Refactor: Replace jQuery utilities with ES6+ alternatives#679

Merged
wenzhixin merged 1 commit into
developfrom
feature/es6-refactor
Feb 28, 2026
Merged

Refactor: Replace jQuery utilities with ES6+ alternatives#679
wenzhixin merged 1 commit into
developfrom
feature/es6-refactor

Conversation

@wenzhixin

@wenzhixin wenzhixin commented Feb 28, 2026

Copy link
Copy Markdown
Owner

🤔 Type of Request

  • Bug fix
  • New feature
  • Improvement
  • Documentation
  • Other

📝 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 native extend()

  • Uses a proven implementation from bootstrap-table
  • Supports both shallow merging: extend({}, obj1, obj2)
  • And deep merging: extend(true, {}, obj)
  • Maintains full API compatibility with jQuery's extend

2. Replace $.each() with native for...of

  • Before: $.each(collection, (i, elm) => { ... })
  • After: for (const [i, elm] of Array.from(collection).entries()) { ... }
  • More idiomatic ES6+ syntax

3. Replace $.inArray() with native Array.prototype.includes()

  • Before: if ($.inArray(option, Constants.METHODS) < 0)
  • After: if (!Constants.METHODS.includes(option))
  • Simpler and more readable

📁 Files Modified

  • src/MultipleSelect.js - Updated to use extend() and for...of
  • src/multiple-select.js - Updated to use extend() and includes()
  • src/utils/index.js - Added extend() and isObject() utilities

✨ Benefits

  • More native: Uses ES6+ features instead of jQuery utilities
  • More maintainable: Less dependency on jQuery's internal API
  • Better performance: Native methods are generally faster
  • Cleaner code: includes() is more intuitive than inArray()
  • Future-proof: Ready for jQuery 4.0+ where some utilities are deprecated

✅ Testing

All existing functionality is preserved. No breaking changes for end users.

🔍 Code Examples

// Before
$.extend({}, Constants.DEFAULTS, options)
$.each(this.$el.children(), (i, elm) => { ... })
if ($.inArray(option, Constants.METHODS) < 0) { ... }

// After
extend({}, Constants.DEFAULTS, options)
for (const [i, elm] of Array.from(this.$el.children()).entries()) { ... }
if (!Constants.METHODS.includes(option)) { ... }

Love multiple-select? Please consider supporting us:
👉 https://opencollective.com/multiple-select/donate

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) to src/utils/index.js and exported it for reuse.
  • Replaced $.extend() usages with extend() in core initialization and option-handling paths.
  • Replaced $.each() loops with for...of iteration and replaced $.inArray() checks with Array.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.

Comment thread src/utils/index.js Outdated
Comment thread src/MultipleSelect.js Outdated
Comment thread src/utils/index.js

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/utils/index.js
Comment thread src/MultipleSelect.js
Comment thread src/MultipleSelect.js
Comment thread src/multiple-select.js

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/utils/index.js
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.
@wenzhixin wenzhixin force-pushed the feature/es6-refactor branch from ef3018a to bb0196a Compare February 28, 2026 03:54
@wenzhixin wenzhixin merged commit d789961 into develop Feb 28, 2026
1 check passed
@wenzhixin wenzhixin deleted the feature/es6-refactor branch February 28, 2026 03:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants