Skip to content

Commit 75c63c0

Browse files
committed
refactor: 如果 props.foo === undefind 不是一个合法的属性值,那应该用比 in 更严格的判断
1 parent db706f2 commit 75c63c0

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ export default class InputNumber extends React.Component {
310310
// https://github.com/ant-design/ant-design/issues/8196
311311
let value = e.target.value.trim().replace(//g, '.');
312312

313-
if ('decimalSeparator' in this.props) {
313+
if (this.props.decimalSeparator !== undefined) {
314314
value = value.replace(this.props.decimalSeparator, '.');
315315
}
316316

@@ -354,7 +354,7 @@ export default class InputNumber extends React.Component {
354354
}
355355

356356
getPrecision(value) {
357-
if ('precision' in this.props) {
357+
if (this.props.precision !== undefined) {
358358
return this.props.precision;
359359
}
360360
const valueString = value.toString();
@@ -374,7 +374,7 @@ export default class InputNumber extends React.Component {
374374
// if this.props.precision is undefined
375375
// https://github.com/react-component/input-number/issues/39
376376
getMaxPrecision(currentValue, ratio = 1) {
377-
if ('precision' in this.props) {
377+
if (this.props.precision !== undefined) {
378378
return this.props.precision;
379379
}
380380
const { step } = this.props;
@@ -521,7 +521,7 @@ export default class InputNumber extends React.Component {
521521
if (this.isNotCompleteNumber(num)) {
522522
return num;
523523
}
524-
if ('precision' in this.props) {
524+
if (this.props.precision !== undefined) {
525525
return Number(Number(num).toFixed(this.props.precision));
526526
}
527527
return Number(num);
@@ -702,7 +702,7 @@ export default class InputNumber extends React.Component {
702702
}
703703

704704
let inputDisplayValueFormat = this.formatWrapper(inputDisplayValue);
705-
if ('decimalSeparator' in this.props) {
705+
if (this.props.decimalSeparator !== undefined) {
706706
inputDisplayValueFormat = inputDisplayValueFormat
707707
.toString()
708708
.replace('.', this.props.decimalSeparator);

0 commit comments

Comments
 (0)