Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set construction pointer for access to a derived function object. #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions classy.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
/* copy prototype and constructor over, reattach $extend and
return the class */
rv.prototype = prototype;
rv.constructor = rv;
rv.prototype.constructor = rv;
rv.$extend = Class.$extend;
rv.$withData = Class.$withData;
return rv;
Expand All @@ -158,4 +158,4 @@

/* export the class */
return Class;
});
});
12 changes: 12 additions & 0 deletions tests/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,15 @@ test('class variable inheritance', function() {
equal(SubSubTest.bar, SubTest.bar, 'SubSubTest.bar is Test.bar');
equal(SubSubTest.foo, 999, 'SubSubTest.foo has been overridden');
});

test('constructor pointer is corrected to class function object', function() {
var
Sheep = Animal.$extend({}),
dolly = Sheep({
name: 'Dolly'
}),
clone = dolly.clone({
name: 'Dolly'
});
ok(clone instanceof Sheep);
});
4 changes: 4 additions & 0 deletions tests/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ var Animal = Class.$extend({

dead: function() {
return (this.health <= 0);
},

clone: function(options) {
return this.constructor(options);
}
});

Expand Down
4 changes: 2 additions & 2 deletions tests/run_tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<html>
<head>
<title>Classy Test Suite</title>
<link rel="stylesheet" href="http://github.com/jquery/qunit/raw/master/qunit/qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="http://github.com/jquery/qunit/raw/master/qunit/qunit.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/qunit/1.23.1/qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/qunit/1.23.1/qunit.js"></script>
<script type="text/javascript" src="../classy.js"></script>
<script type="text/javascript" src="data.js"></script>
<script type="text/javascript" src="core.js"></script>
Expand Down