Permalink
Browse files

* added some jsdoc

* jslint fix
  • Loading branch information...
1 parent be19902 commit ef96fcbc438a61e9b57b9312923e3b4a54591194 Julien Polo committed Feb 14, 2012
Showing with 108 additions and 36 deletions.
  1. +105 −35 es6.js
  2. +3 −1 stj.js
View
@@ -257,7 +257,6 @@
/**
* Math
*/
- /*
(function () {
var
is = Object.is,
@@ -268,94 +267,165 @@
factorial = function factorial(value) {
var result = 1, i;
for (i = value; i > 0; i--) {
- sum = sum * i;
+ result = result * i;
}
- return sum;
+ return result;
},
LN2_INV = 1 / Math.LN2,
LN10_INV = (1 / Math.LN10);
shim(Math, {
- acosh: function acosh(value) {
- return log(value + sqrt(value * value - 1));
+ /**
+ *
+ * @param {number} numberValue
+ * @return {number}
+ */
+ acosh: function acosh(numberValue) {
+ return log(numberValue + sqrt(numberValue * numberValue - 1));
},
- asinh: function asinh(value) {
- return log(value + sqrt(value * value + 1));
+ /**
+ *
+ * @param {number} numberValue
+ * @return {number}
+ */
+ asinh: function asinh(numberValue) {
+ return log(numberValue + sqrt(numberValue * numberValue + 1));
},
- atanh: function atanh(value) {
- return 0.5 * log((1 + value) / (1 - value));
+ /**
+ *
+ * @param {number} numberValue
+ * @return {number}
+ */
+ atanh: function atanh(numberValue) {
+ return 0.5 * log((1 + numberValue) / (1 - numberValue));
},
- cosh: function cosh(value) {
+ /**
+ *
+ * @param {number} numberValue
+ * @return {number}
+ */
+ cosh: function cosh(numberValue) {
+ if (numberValue < 0) {
+ numberValue = -numberValue;
+ }
return (
- (value < 0) ? value = -value :
- (value > 21) ? exp(value) / 2 :
- (exp(value) + exp(-value)) / 2
+ (numberValue > 21) ? exp(numberValue) / 2 :
+ (exp(numberValue) + exp(-numberValue)) / 2
);
},
- expm1: function expm1(value) {
+ /**
+ *
+ * @param {number} numberValue
+ * @return {number}
+ */
+ expm1: function expm1(numberValue) {
var
result = 0,
n = 50, i;
for (i = 1; i < n; i++) {
- result += pow(value, i) / factorial(i);
+ result += pow(numberValue, i) / factorial(i);
}
return result;
},
- hypot: function hypot(x, y) {
- return sqrt(x * x + y * y) || 0;
+ /**
+ * Return the hypothenuse of `sideA`/ `sideB`
+ *
+ * @param {number} sideA
+ * @param {number} sideB
+ * @return {number}
+ */
+ hypot: function hypot(sideA, sideB) {
+ return sqrt(sideA * sideA + sideB * sideB) || 0;
},
- log2: function log2(value) {
- return log(value) * LN2_INV;
+ /**
+ *
+ * @param {number} numberValue
+ * @returns {number}
+ */
+ log2: function log2(numberValue) {
+ return log(numberValue) * LN2_INV;
},
- log10: function log10(value) {
- return log(value) * LN10_INV;
+ /**
+ *
+ * @param {number} numberValue
+ * @returns {number}
+ */
+ log10: function log10(numberValue) {
+ return log(numberValue) * LN10_INV;
},
- log1p: function log1p(value) {
+ /**
+ *
+ * @param {number} numberValue
+ * @returns {number}
+ */
+ log1p: function log1p(numberValue) {
var
result = 0,
n = 50, i, sign = 1;
- if (value <= -1) {
+ if (numberValue <= -1) {
return -Infinity;
}
- if (value < 0 || value > 1) {
- return log(1 + value);
+ if (numberValue < 0 || numberValue > 1) {
+ return log(1 + numberValue);
}
for (i = 1; i < n; i += 1) {
- result += (sign * pow(value, i) / i);
+ result += (sign * pow(numberValue, i) / i);
sign *= -1;
}
return result;
},
+ /**
+ * Return -1 if negative number or 1 else
+ *
+ * @param {number} numberValue
+ * @returns {number}
+ */
sign: function sign(value) {
var number = +value;
return (is(number, NaN) || number === 0) ? number : (number < 0) ? -1 : 1;
},
- sinh: function sinh(value) {
- return (exp(value) - exp(-value)) / 2;
+ /**
+ *
+ * @param {number} numberValue
+ * @returns {number}
+ */
+ sinh: function sinh(numberValue) {
+ return (exp(numberValue) - exp(-numberValue)) / 2;
},
- tanh: function tanh(value) {
- var expV = exp(value),
- expVMinus = exp(-value);
- return (expV - expVMinus) / (expV + expVMinus);
+ /**
+ *
+ * @param {number} numberValue
+ * @returns {number}
+ */
+ tanh: function tanh(numberValue) {
+ var
+ expValue = exp(numberValue),
+ expValueMinus = exp(-numberValue);
+ return (expValue - expValueMinus) / (expValue + expValueMinus);
},
- trunc: function trunc(value) {
- return ~~value;
+ /**
+ *
+ * @param {number} numberValue
+ * @returns {number}
+ */
+ trunc: function trunc(numberValue) {
+ return ~~numberValue;
}
});
- }());*/
+ }());
}));
View
@@ -200,7 +200,9 @@ define("stj/stj", function () {
stj.shim = function shim(object, properties, onProto) {
stj.use_(object, function () {
var
- def = stj.def_,
+ def = typeof object === "function" ? stj.def_ : function (property, descriptor) {
+ stj.defineProperty(object, property, descriptor);
+ },
property;
for (property in properties) {
if (hasOwn.call(properties, property) && !hasOwn.call(object, property)) {

0 comments on commit ef96fcb

Please sign in to comment.