Curing “this.setOptions is not a function” in MooTools 1.2

By  on  

On one of the MooTools 1.2 classes I was working on recently, I kept getting the following annoying JavaScript error:

this.setOptions is not a function

Here's what my code looked like:

//create class
var myClass = new Class({
	
	//options
	options: {
		defaults: {},
		elements: $$('.getme'),
		focus: '',
		override: false,
		assignIds: true
	},
	
	//initialization
	initialize: function(options) {
		//set options
		this.setOptions(options);
		//assign ids, if necessary
		if(this.options.assignIds == true) { this.assign(); }
		//populate them all
		this.populate();
	},
	
	//......

After doing some research, I discovered that I needed to implement Options:

var myClass = new Class({
	
	Implements: [Options],
	
	//......

I think this may be new in MooTools 1.2, as I had never heard of this before. Oh well -- problem solved!

Recent Features

  • By
    Create a CSS Flipping Animation

    CSS animations are a lot of fun; the beauty of them is that through many simple properties, you can create anything from an elegant fade in to a WTF-Pixar-would-be-proud effect. One CSS effect somewhere in between is the CSS flip effect, whereby there's...

  • By
    39 Shirts – Leaving Mozilla

    In 2001 I had just graduated from a small town high school and headed off to a small town college. I found myself in the quaint computer lab where the substandard computers featured two browsers: Internet Explorer and Mozilla. It was this lab where I fell...

Incredible Demos

  • By
    MooTools-Like Element Creation in jQuery

    I really dislike jQuery's element creation syntax. It's basically the same as typing out HTML but within a JavaScript string...ugly! Luckily Basil Goldman has created a jQuery plugin that allows you to create elements using MooTools-like syntax. Standard jQuery Element Creation Looks exactly like writing out...

  • By
    MooTools ContextMenu Plugin

    ContextMenu is a highly customizable, compact context menu script written with CSS, XHTML, and the MooTools JavaScript framework. ContextMenu allows you to offer stylish, functional context menus on your website. The XHTML Menu Use a list of menu items with one link per item. The...

Discussion

  1. That’s a very good tip, I’ve saved that to Snippely so that I’m sure to remember it. This brings up a good point though…

    How drastic are the changes in 1.2? I have a lot of scripts (and use a lot of scripts) that were made using 1.11. I understand 1.2 is better but they aren’t making this easy by 1.) completely reformatting the online documentation and 2.) killing off the user forum. What’s up with that?

    How much trouble have you had in moving to 1.2?

    Hmm…might want to make this topic a separate post in itself actually…

  2. @Tim: I agree with your statement about the out-of-the-blue 1.2 release, lack of demos, and death of the user forum. The issue is that MooTools is an “in-our-spare-time” project (no one gets paid) and they were having major technical issues with their installation of Trac. I don’t mind looking that the actual code myself and experimenting though — builds character, as your grandfather would tell you!

  3. Oh I completely understand. I used to hang out in their IRC channel quite a bit and while it IS an “in-our-spare-time” type project, there are so many developers working on it so often you would almost think otherwise.

    I remember the jump from the below 1 versions to 1.xx and it was much much easier. They didn’t completely revamp their online presence and the forums were there for help. Now all of the script resources that were posted are all gone, the Google user group has only a portion of what information used to be out there and the documentation (in my opinion) is worse from a usability standpoint. It was perfect before.

    Unfortunately moving from 1.11 to 1.2 on our production sites is just going to have to wait…most likely until Aaron redoes the CNET Mootools Primer and help is there to assist in migrating our scripts over.

    It really is a disappointment too because from what I’ve seen 1.2 is really pretty awesome.

  4. Yeah, we also had problems with migrating MooTools 1.1 apps to MooTools 1.2.. It’s like upgrading a complex CMS like Typo3.
    We’ve even developed scripts with the 1.2 beta and the effects only worked in this beta so it’s a bit complicated to do a complete upgrade to 1.2.
    How is it if you’re using the Google AJAX library API? It seems they haven’t upgraded to 1.2 yet.

  5. Alan

    This had to be done in v1.11 also. It was done outside of the class though.

    CLASSNAME.implement(new Options, new Events);

  6. @Alan: Interesting. Thank you!

  7. Bob

    Saved my day!

  8. guy

    idem. thx ;)

  9. How to “cure” this using MooTools 1.4.5?
    I have used this example and I always get TypeError: this.setOptions is not a function ;-(

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!