File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,16 @@ var Department = /** @class */ (function () {
3
3
function Department ( n ) {
4
4
this . name = n ;
5
5
}
6
+
7
+ Department . prototype . describe = function ( ) {
8
+ console . log ( "Department: " + this . name ) ;
9
+ } ;
6
10
return Department ;
7
11
} ( ) ) ;
8
12
var accounting = new Department ( 'Accounting' ) ;
9
- console . log ( accounting ) ;
13
+ accounting . describe ( ) ;
14
+ var accountingCopy = { name : 'newName' , describe : accounting . describe } ;
15
+ //์ฌ๊ธฐ์ undefined๋ฅผ ์ถ๋ ฅํ๋ ์ด์ ๋ describe๊ฐ ์ฐธ์กฐํ๋ ๊ฒ์ด ๋ฌด์์ธ์ง ์ ์ ์๊ธฐ ๋๋ฌธ์ด๋ค.
16
+ //๋ฐ๋ผ์ accountingCopy์ ๊ฐ์ด ์๋ก์ด ๊ฐ์ฒด๋ก ์ฌ์์ฑ์ ํด์ ํ ๋นํ๊ธฐ ์ํด์๋ class์ describeํจ์์ ๋งค๊ฐ๋ณ์์
17
+ //this๋ฅผ ๋ฃ๊ณ ํ์
์ง์ ์ Department๋ก ์ค์ ํ ๋ค(์ฆ, ์ฒญ์ฌ์ง์ ์ฐธ์กฐํ๊ฒ ์ค์ ) accountingCopy์ name ํ๋กํผํฐ๋ฅผ ๊ธฐ์
, ํ ๋นํด์ค์ผ ํ๋ค.
18
+ accountingCopy . describe ( ) ;
Original file line number Diff line number Diff line change @@ -3,7 +3,18 @@ class Department {
3
3
constructor ( n : string ) {
4
4
this . name = n ;
5
5
}
6
+
7
+ describe ( this : Department ) {
8
+ console . log ( `Department: ` + this . name )
9
+ }
6
10
}
7
11
8
12
const accounting = new Department ( 'Accounting' ) ;
9
- console . log ( accounting ) ;
13
+ accounting . describe ( ) ;
14
+
15
+ const accountingCopy = { name : 'newName' , describe : accounting . describe } ;
16
+ //์ฌ๊ธฐ์ undefined๋ฅผ ์ถ๋ ฅํ๋ ์ด์ ๋ describe๊ฐ ์ฐธ์กฐํ๋ ๊ฒ์ด ๋ฌด์์ธ์ง ์ ์ ์๊ธฐ ๋๋ฌธ์ด๋ค.
17
+ //๋ฐ๋ผ์ accountingCopy์ ๊ฐ์ด ์๋ก์ด ๊ฐ์ฒด๋ก ์ฌ์์ฑ์ ํด์ ํ ๋นํ๊ธฐ ์ํด์๋ class์ describeํจ์์ ๋งค๊ฐ๋ณ์์
18
+ //this๋ฅผ ๋ฃ๊ณ ํ์
์ง์ ์ Department๋ก ์ค์ ํ ๋ค(์ฆ, ์ฒญ์ฌ์ง์ ์ฐธ์กฐํ๊ฒ ์ค์ ) accountingCopy์ name ํ๋กํผํฐ๋ฅผ ๊ธฐ์
, ํ ๋นํด์ค์ผ ํ๋ค.
19
+
20
+ accountingCopy . describe ( ) ;
You canโt perform that action at this time.
0 commit comments