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
    6 Things You Didn’t Know About Firefox OS

    Firefox OS is all over the tech news and for good reason:  Mozilla's finally given web developers the platform that they need to create apps the way they've been creating them for years -- with CSS, HTML, and JavaScript.  Firefox OS has been rapidly improving...

  • By
    Welcome to My New Office

    My first professional web development was at a small print shop where I sat in a windowless cubical all day. I suffered that boxed in environment for almost five years before I was able to find a remote job where I worked from home. The first...

Incredible Demos

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!