Skip to content

Commit 5d437ea

Browse files
crisbetoandrewseguin
authored andcommitted
refactor: remove usages of if in checks (#6436)
This is something that came up in #2907 (comment). We shouldn't be using the `if ('someString' in obj)` checks, because they can be broken by minifiers that rename class members.
1 parent f9bd5d4 commit 5d437ea

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

src/lib/core/option/option.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export class MdOption {
145145
focus(): void {
146146
const element = this._getHostElement();
147147

148-
if ('focus' in element) {
148+
if (typeof element.focus === 'function') {
149149
element.focus();
150150
}
151151
}

src/lib/datepicker/datepicker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,9 @@ export class MdDatepicker<D> implements OnDestroy {
278278
if (this._calendarPortal && this._calendarPortal.isAttached) {
279279
this._calendarPortal.detach();
280280
}
281-
if (this._focusedElementBeforeOpen && 'focus' in this._focusedElementBeforeOpen) {
281+
if (this._focusedElementBeforeOpen &&
282+
typeof this._focusedElementBeforeOpen.focus === 'function') {
283+
282284
this._focusedElementBeforeOpen.focus();
283285
this._focusedElementBeforeOpen = null;
284286
}

src/lib/dialog/dialog-container.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export class MdDialogContainer extends BasePortalHost {
150150
const toFocus = this._elementFocusedBeforeDialogWasOpened;
151151

152152
// We need the extra check, because IE can set the `activeElement` to null in some cases.
153-
if (toFocus && 'focus' in toFocus) {
153+
if (toFocus && typeof toFocus.focus === 'function') {
154154
toFocus.focus();
155155
}
156156

src/lib/slide-toggle/slide-toggle.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ describe('MdSlideToggle with forms', () => {
699699
}));
700700

701701
it('should prevent the form from submit when being required', () => {
702-
if ('reportValidity' in inputElement === false) {
702+
if (typeof (inputElement as any).reportValidity === 'undefined') {
703703
// If the browser does not report the validity then the tests will break.
704704
// e.g Safari 8 on Mobile.
705705
return;

0 commit comments

Comments
 (0)