Skip to content

Commit f35f9bc

Browse files
authored
Merge pull request #262682 from Da-nie-elT/update-forin-snippet
Update for-in loop snippet with `Object.hasOwn()`
2 parents d44d16c + a92f6c9 commit f35f9bc

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

extensions/javascript/snippets/javascript.code-snippets

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,11 @@
9898
"prefix": "forin",
9999
"body": [
100100
"for (const ${1:key} in ${2:object}) {",
101-
"\tif (Object.prototype.hasOwnProperty.call(${2:object}, ${1:key})) {",
102-
"\t\tconst ${3:element} = ${2:object}[${1:key}];",
103-
"\t\t$TM_SELECTED_TEXT$0",
104-
"\t}",
101+
"\tif (!Object.hasOwn(${2:object}, ${1:key})) continue;",
102+
"\t",
103+
"\tconst ${3:element} = ${2:object}[${1:key}];",
104+
"\t",
105+
"\t$TM_SELECTED_TEXT$0",
105106
"}"
106107
],
107108
"description": "For-In Loop"

extensions/typescript-basics/snippets/typescript.code-snippets

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,11 @@
152152
"prefix": "forin",
153153
"body": [
154154
"for (const ${1:key} in ${2:object}) {",
155-
"\tif (Object.prototype.hasOwnProperty.call(${2:object}, ${1:key})) {",
156-
"\t\tconst ${3:element} = ${2:object}[${1:key}];",
157-
"\t\t$TM_SELECTED_TEXT$0",
158-
"\t}",
155+
"\tif (!Object.hasOwn(${2:object}, ${1:key})) continue;",
156+
"\t",
157+
"\tconst ${3:element} = ${2:object}[${1:key}];",
158+
"\t",
159+
"\t$TM_SELECTED_TEXT$0",
159160
"}"
160161
],
161162
"description": "For-In Loop"

0 commit comments

Comments
 (0)