Skip to content

Commit

Permalink
Fixes #2687 - Set the $family property to null for Class
Browse files Browse the repository at this point in the history
This fixes typeOf, when a Class extends a Native Type (like String)
which has the $family property set.

See this issue: #2687

Updated code to match style guidelines.
  • Loading branch information
nbish11 authored and arian committed Feb 16, 2015
1 parent a1e68c7 commit 9cb9ddb
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions Source/Class/Class.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var Class = this.Class = new Type('Class', function(params){
reset(this);
if (newClass.$prototyping) return this;
this.$caller = null;
this.$family = null;
var value = (this.initialize) ? this.initialize.apply(this, arguments) : this;
this.$caller = this.caller = null;
return value;
Expand Down
63 changes: 63 additions & 0 deletions Specs/Class/Class.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,67 @@ describe('Class toString', function(){

});

describe('Class.toElement', function(){

var MyParentElement = new Class({

initialize: function(element){
this.element = element;
},

toElement: function(){
return this.element;
}

});

var MyChildElement = new Class({

Extends: MyParentElement,

initialize: function(element){
this.parent(element);
}

});

var MyArrayElement = new Class({

Extends: Array,

initialize: function(element){
this.element = element;
},

toElement: function(){
return this.element;
}

});

it('should return an element when a class instance is passed to document.id', function(){
var element = new Element('div', {'class': 'my-element'});
var instance = new MyParentElement(element);

expect(document.id(instance)).toBe(element);
});

it('should call the toElement() method in parent class if none is defined in child', function(){
var element = new Element('div', {'class': 'my-element'});
var instance = new MyChildElement(element);

expect(document.id(instance)).toBe(element);
expect(instance instanceof MyParentElement).toEqual(true);
});

it('should call toElement() when extending natives (String, Array, Object)', function(){
var element = new Element('div', {'class': 'my-element'});
var instance = new MyArrayElement(element);

expect(document.id(instance)).toBe(element);
expect(instance instanceof Array).toEqual(true);
});

});

})();

0 comments on commit 9cb9ddb

Please sign in to comment.