Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk3 min

How to Build Attractive.js Custom Actions, From One-Liners to Classes

Attractive.js custom actions can grow from a short js: expression to a registered function or a class with run(). Learn how registration, context, helpers, and the unsafe-eval CSP requirement affect that choice.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Attractive.js custom actions can start as a short js: expression, become a registered function when the behavior needs a name, and grow into a class with run() when it needs more structure. Functions and classes use the same addActions registration pattern. One important limit: the js: shortcut uses new Function(), so it requires unsafe-eval in your site’s Content Security Policy (CSP).

Choose an action form that fits the behavior

The practical progression is based on how much structure the behavior needs—not on separate registration systems. The Attractive.js author describes the options in a custom-actions guide; the examples below reflect that guide rather than independent testing.

As an Amazon Associate I earn from qualifying purchases.

Form Best fit Main consideration
js: expression A short, one-off expression Compact, but uses new Function() and requires unsafe-eval in the CSP.
Registered function A named behavior with modest logic that may be reused Receives the element and a context object; register it through addActions.
Class with run() A larger behavior that benefits from instance structure or helpers Uses the same addActions configuration; the optional Action base class provides additional helpers.

Start small with a js: expression

For a tiny behavior that does not merit a named action, the guide describes using js: to evaluate a JavaScript expression on the element. It goes through the regular action pipeline, so event handling and attributes such as data-debounce and data-delay still apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The trade-off is security policy: the implementation uses new Function(). As the author puts it, “It runs new Function() under the hood (which needs unsafe-eval in your CSP).” If your CSP does not allow unsafe-eval, do not use this shortcut; move the behavior to a registered function or class instead.

Promote reusable logic to a registered function

When an expression has grown beyond a one-off, give it a name and register it as an action. The guide’s example shape is a function such as sharePage(element, { dataset }), added through Attractive.activate({ addActions: { sharePage } }).

The function receives the triggering element and a context object. The documented context includes:

  • value: the action value.
  • target and targets: target information.
  • event: the event associated with the action.
  • dataset: the element’s data attributes.

This keeps a modest action easy to reuse without adding class structure it does not yet need. The central API promise is consistent registration: a function is supplied through addActions, just as a class is.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a class when the action needs structure

For behavior that has grown enough to benefit from instance methods or helpers, the guide describes registering a class with a run() method through the same addActions configuration. The instance receives element and options.

An optional Action base class adds value, dataset, and a dispatchEvent helper. In the guide’s Reorder example, the action uses that helper to emit reorder:done with IDs. That illustrates the class form’s value: it offers a place for a larger action’s behavior and supporting methods, rather than requiring every action to begin as a class.

Organize several actions without changing registration

For a small collection of actions, the author suggests keeping each in its own file, gathering the imports in a barrel module, and passing the resulting object to Attractive.activate({ addActions: actions }). This is an organizational option, not a required project convention. The important point is that the registration interface remains the same as the collection grows.

Handle action lifecycle and errors

The guide describes three hooks for managing action execution:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • beforeAction runs before each action; returning false cancels it.
  • afterAction runs after a successful action.
  • onError handles an action that throws.

According to the author, an error does not prevent the rest of a chained action from continuing, and a global Attractive.onError fallback can be used for monitoring integration. These are claims from the implementation guide, not independently verified behavior; check the version and documentation you use before relying on them in a critical flow.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Keep adjacent features separate from the action ladder

The same guide mentions optional keyboard support, including event keys and global hotkeys; integration with native browser constraint validation; a shared JSON reactive store with text bindings; and Attractive Element, a custom-element base class that scopes actions and targets. These are related capabilities, not prerequisites for choosing between an inline expression, a function, and a class.

A separate overview published on 10 September 2026 described Attractive.js 1.0.0 as a pre-release at that time, introduced @action and @target syntax and bundled actions, and positioned the library as a lightweight declarative option for small interactions in static and server-rendered apps. That is historical publication-time status, not confirmation of the current release state. The overview also reported a full build of about 7 KB gzipped and a core build below 5 KB with bundler qualification; those are author-reported figures, not independent benchmarks, and they are not necessary to choose an action form.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.