String.raw

String.raw() ์ •์  ๋ฉ”์†Œ๋“œ๋Š” template Iiterals์˜ ํƒœ๊ทธ ํ•จ์ˆ˜์ด๋‹ค. Python์˜ r prefix์™€ ๋ฌธ์ž์—ด ๋ฆฌํ„ฐ๋Ÿด์˜ ๊ฒฝ์šฐ C#์˜ @ ์ ‘๋‘์‚ฌ์™€ ์œ ์‚ฌํ•˜๋‹ค. (๊ทธ๋Ÿฌ๋‚˜ ๋™์ผํ•˜์ง€ ์•Š์Œ) template ๋ฌธ์ž์—ด์˜ ์›์‹œ ๋ฌธ์ž์—ด ํ˜•ํƒœ, ๋Œ€์ฒด(์˜ˆ ${foo}) ์ฒ˜๋ฆฌ๊ฐ€ ๋˜์ง€๋งŒ ์ด์Šค์ผ€์ดํ”„(์˜ˆ: \n)๋Š” ์ฒ˜๋ฆฌ๋˜์ง€ ์•Š๋Š”๋‹ค.

// "C:Developmentprofileaboutme.html"
// raw๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•˜์„ ๋•Œ
`C:\Development\profile\aboutme.html`;

// ๋ฐฑ์Šฌ๋ž˜์‹œ๊ฐ€ ๋น ์ง€์ง€ ์•Š๊ฒŒ ์œˆ๋„์šฐ ํŒŒ์ผ ๊ฒฝ๋กœ๋ฅผ ๋‹ด๋Š” ๋ณ€์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด๋ผ
const filePath = String.raw`C:\Development\profile\aboutme.html`;


console.log('The file was uploaded from:' + filePath); // The file was uploaded from:C:\Development\profile\aboutme.html

Syntax

String.raw(callSite, ...substitutions)

string.raw`templateString`

Parameters

callSite

{ raw: ['foo', 'bar', 'baz'] } ๊ฐ™์ด ์ž˜ ํ˜•์„ฑ๋œ template๋ฅผ ํ˜ธ์ถœํ•˜๋Š” site object

...substitution

template string, ํ•„์š”ํ•œ ๊ฒฝ์šฐ ๊ต์ฒดํ•œ๋‹ค (${...}).

Return value

์ฃผ์–ด์ง„ template ๋ฌธ์ž์—ด์˜ ์›์‹œ ๋ฌธ์ž์—ด์ด๋‹ค.

์˜ˆ์™ธ

site object๊ฐ€ ์ž˜๋ชป๋œ ํ˜•์„ฑ์ด๋ฉด TypeError(๊ฐ’์ด ๊ธฐ๋Œ€ํ•˜๋˜ ์ž๋ฃŒํ˜•์ด ์•„๋‹ˆ๋ผ์„œ ์—ฐ์‚ฐ์„ ํ•  ์ˆ˜ ์—†์„ ๋•Œ ๋ฐœ์ƒํ•˜๋Š” ์˜ค๋ฅ˜) ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.

Description

๋Œ€๋ถ€๋ถ„์˜ ๊ฒฝ์šฐ, String.raw() ๋Š” template string๊ณผ ๊ฐ™์ด ์‚ฌ์šฉ๋œ๋‹ค.

์œ„์—์„œ ์–ธ๊ธ‰ํ•œ ์ฒซ๋ฒˆ์งธ ๊ตฌ๋ฌธ์€ ๊ฑฐ์˜ ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š”๋‹ค. JavaScript ์—”์ง„์ด (๋‹ค๋ฅธ ํƒœ๊ทธ ๊ธฐ๋Šฅ๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ) ์ ์ ˆํ•œ ์ธ์ˆ˜๋กœ ํ˜ธ์ถœํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

String.raw() ํ…œํ”Œ๋ฆฟ ๋ฌธ์ž์—ด์˜ ์œ ์ผํ•œ built-in tag function์ด๋‹ค. ๊ธฐ๋ณธ ํ…œํ”Œ๋ฆฟ ๊ธฐ๋Šฅ๊ณผ ๋™์ผํ•˜๊ฒŒ ์ž‘๋™ํ•˜๋ฉฐ ์—ฐ๊ฒฐ์„ ์ˆ˜ํ–‰ํ•œ๋‹ค. JavaScript ์ฝ”๋“œ๋กœ ๋‹ค์‹œ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค.

String.raw() ์‚ฌ์šฉ

Browser compatibility

IE ๋†‰, Opera ๋†‰, ์•ˆ๋“œ๋กœ์ด๋“œ ์›น๋ทฐ ๋†‰, ์•ˆ๋“œ๋กœ์ด๋“œ ์˜คํŽ˜๋ผ ๋†‰

Last updated

Was this helpful?