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
    5 HTML5 APIs You Didn’t Know Existed

    When you say or read "HTML5", you half expect exotic dancers and unicorns to walk into the room to the tune of "I'm Sexy and I Know It."  Can you blame us though?  We watched the fundamental APIs stagnate for so long that a basic feature...

  • By
    JavaScript Promise API

    While synchronous code is easier to follow and debug, async is generally better for performance and flexibility. Why "hold up the show" when you can trigger numerous requests at once and then handle them when each is ready?  Promises are becoming a big part of the JavaScript world...

Incredible Demos

  • By
    Introducing MooTools NextPrev

    One thing I love doing is duplicating OS functionalities. One of the things your OS allows you to do easily is move from one item to another. Most of the time you're simply trying to get to the next or the previous item.

  • By
    Google-Style Element Fading Using MooTools or jQuery

    Google recently introduced an interesting effect to their homepage: the top left and top right navigation items don't display until you move your mouse or leave the search term box. Why? I can only speculate that they want their homepage as...

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!