Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

jQuery Plugin Builder

Write jQuery plugins in Haxe. Basic knowledge of writing jQuery plugins in pure javascript would be helpful.

Step 1. Write the Plugin Function

All classes that implements the IPlugin interface will have their public static functions whose name beginning in "plugin" injected with a _this variable. _this refers to the this in the javascript context.

Under the hood it is simply a Haxe expression added to the beginning of the function:

var _this:JQuery = untyped __js__("this");

Learn more about this and creating plugins from the jQuery Learning Center.


package ;
import js.JQuery;
// you can also choose to use the jQuery.JQuery from the jQueryExtern library

class MyPlugin implements IPlugin
	public static function pluginWithoutParameter():JQuery
		// "_this" refers to "this" in the javascript context
		//for chaining
		return _this;
	public static function pluginWithParameter(param:String):JQuery
		// "_this" refers to "this" in the javascript context
		//for chaining
		return _this;		
	public static function someUtilityFunction():Void
		_this; // "_this" is undefined because the name of this function does not start with "plugin"	

Note that the IPlugin interface is empty, meaning that no functions or properties have to be implemented.

Step 2. Register as a jQuery Plugin

Call JQueryPlugin.registerPlugin() to register the function as a plugin of jQuery. You may also call JQueryPlugin.registerUtility to register a utility function for jQuery.


class Main
	static function main() 
		JQueryPlugin.registerPlugin("plugin", MyPlugin.pluginWithoutParameter);
		// example usage in javascript: $("body").plugin();
		JQueryPlugin.registerPlugin("anotherPlugin", MyPlugin.pluginWithParameter); 
		// example usage in javascript: $("body").anotherPlugin(someParameter);
		JQueryPlugin.registerUtility("util", MyPlugin.someUtilityFunction); 
		// example usage in javascript: $.util();		

Note that your haxe-generated javascript program must be run after importing the jQuery.

Example html

	<script src="//"></script>
	<script src="Main.js"></script> <!--Your Haxe-generated program-->


Write jQuery plugins in Haxe




No releases published


No packages published


You can’t perform that action at this time.