Skip to content
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ Following are the operators which can be overloaded with the desired overload fu
| 38 | &= | __andAssign | Assignment |
| 39 | \|= | __orAssign | Assignment |
| 40 | ^= | __xorAssign | Assignment |
| 41 | `**` | __exponent | Binary |


##Design Consideration / Very IMP / Must Read##
Expand Down
6 changes: 5 additions & 1 deletion lib/overload.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ var funcNames = {
'>>>=': '__zeroFillRightShiftAssign',
'&=': '__andAssign',
'|=': '__orAssign',
'^=': '__xorAssign'
'^=': '__xorAssign',
'**': '__exponent'
};

//The AST Walker And Transformer
Expand Down Expand Up @@ -353,6 +354,9 @@ cons.forEach(function (constructor) {
defineDefaultProp(constructor, funcNames['^='], function (o) {
return o ^= this;
});
defineDefaultProp(constructor, funcNames['**'], function (o) {
return o ** this;
});
});
/* jshint ignore:end */

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
"homepage": "https://github.com/kushal-likhi/operator-overloading-js",
"dependencies": {
"escodegen": "^1.4.1",
"esprima": "^1.2.2"
"esprima": "^4.0.1"
}
}
7 changes: 7 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ describe('Operator overloading Test Suite', function () {
done();
});

it('should overload ** operator', function (done) {
overload(function () {
assertEqual((33 ** 22), '33**22');
})();
done();
});

it('should overload - operator', function (done) {
overload(function () {
assertEqual((33 - 22), '33-22');
Expand Down