IAmTheRockstar

Yes. Yes I am.
Extending YUI 3's Plugin
March 18 2011

Every time want to create a YUI 3 Plugin, I always run into this same problem. I'm sick of forgetting this, so I'm going to blog about it, in hopes that it will help me remember. Here's my code until a few minutes ago:

YUI.add('formPlugin', function(Y) {

    var FormPlugin = Y.Base.create('formPlugin', Y.Plugin, [], {}, {});

}, '1.0', {requires: ['base', 'plugin']});

This makes YUI very angry. What's worse is that it gets swallowed in YUI's error handling, so you don't even get good line numbers. The console spits out Uncaught TypeError: Cannot read property 'constructor' of undefined--It kinda provides hints, but it required me to get out ye ol' debugger to figure it out.

The problem is actually very easy. Don't extend Y.Plugin You should be extending Y.Plugin.Base, and the documentation says that, but I keep forgetting.

Don't let it happen to you.

All opinions expressed here constitute my personal opinion, and do not necessarily represent the opinion of any other organization or person, including, but not limited to, my fellow employees, my employer, its clients or their agents.