Permalink
Browse files

update klass to not bubble constructor with initialize method

  • Loading branch information...
1 parent 413b2c2 commit 700e1eb6d86ed78caa9a2d675673f648e9a54b2e @fat fat committed Apr 21, 2011
Showing with 31 additions and 6 deletions.
  1. +3 −2 klass.js
  2. +1 −1 klass.min.js
  3. +1 −1 package.json
  4. +3 −2 src/klass.js
  5. +23 −0 test/tests.js
View
@@ -48,10 +48,11 @@
_constructor = isFunction ? o : this,
_methods = isFunction ? {} : o,
fn = function () {
- fromSub || isFn(o) && supr.apply(this, arguments);
- _constructor.apply(this, arguments);
if (this.initialize) {
this.initialize.apply(this, arguments);
+ } else {
+ fromSub || isFn(o) && supr.apply(this, arguments);
+ _constructor.apply(this, arguments);
}
};
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,7 +1,7 @@
{
"name": "klass",
"description": "JavaScript Class provider designed to provide a classical interface to prototypal inheritance",
- "version": "1.0.2",
+ "version": "1.0.3",
"homepage": "http://dustindiaz.com/klass",
"authors": ["Dustin Diaz <@ded>", "Jacob Thornton <@fat>"],
"repository": {
View
@@ -41,10 +41,11 @@
_constructor = isFunction ? o : this,
_methods = isFunction ? {} : o,
fn = function () {
- fromSub || isFn(o) && supr.apply(this, arguments);
- _constructor.apply(this, arguments);
if (this.initialize) {
this.initialize.apply(this, arguments);
+ } else {
+ fromSub || isFn(o) && supr.apply(this, arguments);
+ _constructor.apply(this, arguments);
}
};
View
@@ -358,5 +358,28 @@ sink('klass', function (test, ok, before, after) {
});
+ test('object literal with initialize shouldn\'t bubble constructor', 1, function () {
+ var Foo = $k({
+ initialize: function() {
+ ok(true, 'object literal with initialize shouldn\'t bubble constructor');
+ }
+ });
+
+ var Bar = Foo.extend({
+ initialize: function() {
+ ok(true, 'object literal with initialize shouldn\'t bubble constructor');
+ }
+ });
+
+ var Baz = Bar.extend({
+ initialize: function() {
+ ok(true, 'object literal with initialize shouldn\'t bubble constructor');
+ }
+ });
+
+ //should only fire Baz's init
+ var baz = new Baz();
+ })
+
});
start();

0 comments on commit 700e1eb

Please sign in to comment.