This project is archived and is in readonly mode.

#72 ✓resolved
fnordfish

Class breaks Hash options

Reported by fnordfish | May 31st, 2008 @ 10:20 AM | in 1.2.1

Hashes in options of Class-Objects will get a simple object:

var foo = new Class({

    options: {
        'h': new Hash({'h':'h'})
    },

    a: new Hash({'a':'a'}),

    initialize: function(options)
    {
        this.setOptions(options);
        this.b = new Hash({'b':'b'});

        /* test on the Hash.each function to exist */
        console.log(this.options.h.each);    /*mootools 1.2r1553: undefined; mootools 1.11: function() */
        console.log(this.a.each);            /*mootools 1.2r1553: undefined; mootools 1.11: function() */
        console.log(this.b.each);            /*mootools 1.2r1553: function(); mootools 1.11: function() */
    }
});

foo.implement(new Options());

new foo();

Figured out, that the $unlink function called on a hash will not return a new Hash (like it does for objects and arrays), but it's object representation.

A possible fix to $unlink():

function $unlink(object){
	var unlinked;
	
	switch ($type(object)){
		case 'object':
			unlinked = {};
			for (var p in object) unlinked[p] = $unlink(object[p]);
		break;
		case 'hash':
			unlinked = new Hash($unlink(object.getClean()));
		break;
		case 'array':
			unlinked = [];
			for (var i = 0, l = object.length; i < l; i++) unlinked[i] = $unlink(object[i]);
		break;
		default: return object;
	}
	
	return unlinked;
};

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

Referenced by

Pages