Redactor extension plugin loading JS before Redactor.js As I want to use two different Redactor plugins, table.js and properties.js, I decided to write a simple Craft Plugin to load the JS using includeJsResouce in the init() function, as so;

function init() {

    if ( craft()-&gt;request-&gt;isCpRequest() &amp;&amp; craft()-&gt;userSession-&gt;isLoggedIn() )
    {
        craft()-&gt;templates-&gt;includeJsResource('myextensions/js/properties.js');
        craft()-&gt;templates-&gt;includeJsResource('myextensions/js/table.js');
    }

}


However, I have found that these JS files are being loaded in the HTML before the Redactor.js file, so I get a JS error in the console, as Redactor is undefined. [Uncaught TypeError: Cannot read property 'prototype' of undefined]

Is there a way to ensure that my plugin JS is loaded after Redactor that does not entail hacking the core of Craft?

The version of Craft I am using is the current, Craft Pro 2.5.2753.
You need to alter your properties.js and table.js files. Instead of assigning the plugin function to $.Redactor.prototype you should assign it to the RedactorPlugins object. 

Standard Redactor Plugin setup:

$.Redactor.prototype.myplugin = function() {
    return {
    // Plugin code here...
    }
}


Craft CMS Redactor Plugin setup:

// Initialize the RedactorPlugins object if it doesn't exist
if ( !RedactorPlugins ) { var RedactorPlugins = {}; }

// Assign the redactor plugin function
RedactorPlugins.myplugin = function() {
    return {
    // Plugin code here...
    }
}


I'm not sure where the documentation on this is, but you can see it in Pixel &amp; Tonic's own RedactorClips plugin here:  https://github.com/pixelandtonic/RedactorClips/blob/master/redactorclips/RedactorClipsPlugin.php