-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
"use strict"; | ||
function Calculator(value) { | ||
this.value = value; | ||
} | ||
// alias | ||
Calculator.fn = Calculator.prototype; | ||
export default Calculator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
"use strict"; | ||
import assert from "assert"; | ||
import calculator from "./calculator"; | ||
import "./calculator-plugin"; // Extend | ||
|
||
var resultValue = calculator(0).add(10).multi(10).value; | ||
assert.equal(resultValue, 10 * 10); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"use strict"; | ||
import calculator from "./calculator"; | ||
calculator.fn.add = function (x) { | ||
this.value += x; | ||
return this; | ||
}; | ||
calculator.fn.sub = function (x) { | ||
this.value -= x; | ||
return this; | ||
}; | ||
calculator.fn.multi = function (x) { | ||
this.value *= x; | ||
return this; | ||
}; | ||
calculator.fn.div = function (x) { | ||
this.value /= x; | ||
return this; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
"use strict"; | ||
function calculator(value) { | ||
if (!(this instanceof calculator)) { | ||
return new calculator(value); | ||
} | ||
this.value = value; | ||
} | ||
// alias | ||
calculator.fn = calculator.prototype; | ||
export default calculator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// LICENSE : MIT | ||
"use strict"; | ||
import assert from "power-assert"; | ||
import calculator from "../../src/jQuery/calculator"; | ||
import "../../src/jQuery/calculator-plugin"; | ||
describe("calculator-plugin", function () { | ||
describe("#add", function () { | ||
it("should add value", function () { | ||
assert.equal(calculator(0).add(10).value, 10); | ||
}); | ||
}); | ||
describe("#sub", function () { | ||
it("should subtraction value", function () { | ||
assert.equal(calculator(0).sub(10).value, -10); | ||
}); | ||
}); | ||
describe("#multi", function () { | ||
it("should multiply value", function () { | ||
assert.equal(calculator(0).add(10).multi(10).value, 10 * 10); | ||
}); | ||
}); | ||
describe("#div", function () { | ||
it("should subtraction value", function () { | ||
assert.equal(calculator(0).add(10).div(2).value, 10 / 2); | ||
}); | ||
}); | ||
}); |