Slide 1

Slide 1 text

ΠϯϑϥΤϯδχΞ͕ ڭ͑ΔJSͷܕ ͨʹ͠@tanishi345

Slide 2

Slide 2 text

ॳΊ·ͯ͠ • ͨʹ͠(@tanishi345) • (ʹΘ͔)ΠϯϑϥΤϯδχΞ

Slide 3

Slide 3 text

ͳΜͰΠϯϑϥ΍ͬͯΔͷʁ

Slide 4

Slide 4 text

ࠓ೔͸JSͷ࿩Λ͠·͢

Slide 5

Slide 5 text

͔Θ͍͍Ͱ͢ΑͶ

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Ͱ͸ͳͯ͘

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

͜ͷ୹ظؒͰ ͜͜·ͰϑϨʔϜϫʔΫ͕ ཚཱ͢Δݴޠ ·ͬͨ͘খֶੜ(JS)͸ ࠷ߴͩͥ

Slide 10

Slide 10 text

ͱ͍͏Θ͚Ͱ

Slide 11

Slide 11 text

JSͷܕͷ࿩Λ͠·͢

Slide 12

Slide 12 text

໰୊Ͱ͢

Slide 13

Slide 13 text

console.log(‘1’ + 0)

Slide 14

Slide 14 text

࣮ࡍʹ΍ͬͯΈͨ

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

਺ࣈͱจࣈྻΛ଍͢ͱ จࣈྻʹͳΔʁ

Slide 17

Slide 17 text

Reference number ECMA-123:2009 © Ecma International 2009 ECMA-262 8th Edition / June 2017 ECMAScript® 2017 Language Specification IUUQTXXXFDNBJOUFSOBUJPOBMPSHQVCMJDBUJPOTTUBOEBSET&DNBIUN

Slide 18

Slide 18 text

NOTE The addition operator either performs string concatenation or numeric addition. AdditiveExpression : AdditiveExpression + MultiplicativeExpression 1. Let lref be the result of evaluating AdditiveExpression. 2. Let lval be ? GetValue(lref). 3. Let rref be the result of evaluating MultiplicativeExpression. 4. Let rval be ? GetValue(rref). 5. Let lprim be ? ToPrimitive(lval). 6. Let rprim be ? ToPrimitive(rval). 7. If Type(lprim) is String or Type(rprim) is String, then a. Let lstr be ? ToString(lprim). b. Let rstr be ? ToString(rprim). c. Return the String that is the result of concatenating lstr and rstr. 8. Let lnum be ? ToNumber(lprim). 9. Let rnum be ? ToNumber(rprim). 10. Return the result of applying the addition operation to lnum and rnum. See the Note below 12.8.5. NOTE 1 No hint is provided in the calls to ToPrimitive in steps 5 and 6. All standard objects except 12.8.3 The Addition Operator ( + ) 12.8.3.1 Runtime Semantics: Evaluation

Slide 19

Slide 19 text

ͳΜ͔೉ͦ͠͏…

Slide 20

Slide 20 text

NOTE The addition operator either performs string concatenation or numeric addition. AdditiveExpression : AdditiveExpression + MultiplicativeExpression 1. Let lref be the result of evaluating AdditiveExpression. 2. Let lval be ? GetValue(lref). 3. Let rref be the result of evaluating MultiplicativeExpression. 4. Let rval be ? GetValue(rref). 5. Let lprim be ? ToPrimitive(lval). 6. Let rprim be ? ToPrimitive(rval). 7. If Type(lprim) is String or Type(rprim) is String, then a. Let lstr be ? ToString(lprim). b. Let rstr be ? ToString(rprim). c. Return the String that is the result of concatenating lstr and rstr. 8. Let lnum be ? ToNumber(lprim). 9. Let rnum be ? ToNumber(rprim). 10. Return the result of applying the addition operation to lnum and rnum. See the Note below 12.8.5. NOTE 1 No hint is provided in the calls to ToPrimitive in steps 5 and 6. All standard objects except 12.8.3 The Addition Operator ( + ) 12.8.3.1 Runtime Semantics: Evaluation

Slide 21

Slide 21 text

ग़ͯ͘Δؔ਺͸5ͭ • GetValue • ToPrimitive • Type • ToString • ToNumber

Slide 22

Slide 22 text

NOTE The addition operator either performs string concatenation or numeric addition. AdditiveExpression : AdditiveExpression + MultiplicativeExpression 1. Let lref be the result of evaluating AdditiveExpression. 2. Let lval be ? GetValue(lref). 3. Let rref be the result of evaluating MultiplicativeExpression. 4. Let rval be ? GetValue(rref). 5. Let lprim be ? ToPrimitive(lval). 6. Let rprim be ? ToPrimitive(rval). 7. If Type(lprim) is String or Type(rprim) is String, then a. Let lstr be ? ToString(lprim). b. Let rstr be ? ToString(rprim). c. Return the String that is the result of concatenating lstr and rstr. 8. Let lnum be ? ToNumber(lprim). 9. Let rnum be ? ToNumber(rprim). 10. Return the result of applying the addition operation to lnum and rnum. See the Note below 12.8.5. NOTE 1 No hint is provided in the calls to ToPrimitive in steps 5 and 6. All standard objects except 12.8.3 The Addition Operator ( + ) 12.8.3.1 Runtime Semantics: Evaluation

Slide 23

Slide 23 text

false. The following abstract operations are used in this speci ication to operate on references: 1. ReturnIfAbrupt(V). 2. If Type(V) is not Reference, return V. 3. Let base be GetBase(V). 4. If IsUnresolvableReference(V) is true, throw a ReferenceError exception. 5. If IsPropertyReference(V) is true, then a. If HasPrimitiveBase(V) is true, then i. Assert: In this case, base will never be unde ined or null. ii. Set base to ! ToObject(base). b. Return ? base.[[Get]](GetReferencedName(V), GetThisValue(V)). 6. Else base must be an Environment Record, a. Return ? base.GetBindingValue(GetReferencedName(V), IsStrictReference(V)) (see 8.1.1). NOTE The object that may be created in step 5.a.ii is not accessible outside of the above abstract operation and the ordinary object [[Get]] internal method. An implementation might 6.2.4.1 GetValue ( V )

Slide 24

Slide 24 text

ઌʹType͕ग़͖ͯ·ͨ͠

Slide 25

Slide 25 text

ECMAScriptͷܕ • The Undeined Type • The Null Type • The Boolean Type • The String Type • The Symbol Type • The Number Type • The Object Type

Slide 26

Slide 26 text

false. The following abstract operations are used in this speci ication to operate on references: 1. ReturnIfAbrupt(V). 2. If Type(V) is not Reference, return V. 3. Let base be GetBase(V). 4. If IsUnresolvableReference(V) is true, throw a ReferenceError exception. 5. If IsPropertyReference(V) is true, then a. If HasPrimitiveBase(V) is true, then i. Assert: In this case, base will never be unde ined or null. ii. Set base to ! ToObject(base). b. Return ? base.[[Get]](GetReferencedName(V), GetThisValue(V)). 6. Else base must be an Environment Record, a. Return ? base.GetBindingValue(GetReferencedName(V), IsStrictReference(V)) (see 8.1.1). NOTE The object that may be created in step 5.a.ii is not accessible outside of the above abstract operation and the ordinary object [[Get]] internal method. An implementation might 6.2.4.1 GetValue ( V )

Slide 27

Slide 27 text

ཁ͸஋Λฦؔ͢਺Ͱ͢

Slide 28

Slide 28 text

NOTE The addition operator either performs string concatenation or numeric addition. AdditiveExpression : AdditiveExpression + MultiplicativeExpression 1. Let lref be the result of evaluating AdditiveExpression. 2. Let lval be ? GetValue(lref). 3. Let rref be the result of evaluating MultiplicativeExpression. 4. Let rval be ? GetValue(rref). 5. Let lprim be ? ToPrimitive(lval). 6. Let rprim be ? ToPrimitive(rval). 7. If Type(lprim) is String or Type(rprim) is String, then a. Let lstr be ? ToString(lprim). b. Let rstr be ? ToString(rprim). c. Return the String that is the result of concatenating lstr and rstr. 8. Let lnum be ? ToNumber(lprim). 9. Let rnum be ? ToNumber(rprim). 10. Return the result of applying the addition operation to lnum and rnum. See the Note below 12.8.5. NOTE 1 No hint is provided in the calls to ToPrimitive in steps 5 and 6. All standard objects except 12.8.3 The Addition Operator ( + ) 12.8.3.1 Runtime Semantics: Evaluation

Slide 29

Slide 29 text

other speci ication types are used with these operations. The abstract operation ToPrimitive takes an input argument and an optional argument PreferredType. The abstract operation ToPrimitive converts its input argument to a non-Object type. If an object is capable of converting to more than one primitive type, it may use the optional hint PreferredType to favour that type. Conversion occurs according to the following algorithm: 1. Assert: input is an ECMAScript language value. 2. If Type(input) is Object, then a. If PreferredType was not passed, let hint be "default". b. Else if PreferredType is hint String, let hint be "string". c. Else PreferredType is hint Number, let hint be "number". 7.1.1 ToPrimitive ( input [ , PreferredType ] ) d. Let exoticToPrim be ? GetMethod(input, @@toPrimitive). e. If exoticToPrim is not unde ined, then i. Let result be ? Call(exoticToPrim, input, « hint »). ii. If Type(result) is not Object, return result. iii. Throw a TypeError exception. f. If hint is "default", set hint to "number". g. Return ? OrdinaryToPrimitive(input, hint). 3. Return input. NOTE When ToPrimitive is called with no hint, then it generally behaves as if the hint were

Slide 30

Slide 30 text

Object͡Όͳ͍ͷͰ

Slide 31

Slide 31 text

NOTE The addition operator either performs string concatenation or numeric addition. AdditiveExpression : AdditiveExpression + MultiplicativeExpression 1. Let lref be the result of evaluating AdditiveExpression. 2. Let lval be ? GetValue(lref). 3. Let rref be the result of evaluating MultiplicativeExpression. 4. Let rval be ? GetValue(rref). 5. Let lprim be ? ToPrimitive(lval). 6. Let rprim be ? ToPrimitive(rval). 7. If Type(lprim) is String or Type(rprim) is String, then a. Let lstr be ? ToString(lprim). b. Let rstr be ? ToString(rprim). c. Return the String that is the result of concatenating lstr and rstr. 8. Let lnum be ? ToNumber(lprim). 9. Let rnum be ? ToNumber(rprim). 10. Return the result of applying the addition operation to lnum and rnum. See the Note below 12.8.5. NOTE 1 No hint is provided in the calls to ToPrimitive in steps 5 and 6. All standard objects except 12.8.3 The Addition Operator ( + ) 12.8.3.1 Runtime Semantics: Evaluation

Slide 32

Slide 32 text

ͲͪΒ͔͕StringܕͳΒ

Slide 33

Slide 33 text

console.log(‘1’ + 0)

Slide 34

Slide 34 text

console.log(‘1’ + 0)

Slide 35

Slide 35 text

ToString

Slide 36

Slide 36 text

ͭ·Γ console.log(‘1’ + 0) => console.log(‘1’ + ‘0’) => ’10’

Slide 37

Slide 37 text

console.log(+‘1’)

Slide 38

Slide 38 text

࣮ࡍʹ΍ͬͯΈͨ

Slide 39

Slide 39 text

NOTE The unary + operator converts its operand to Number type. UnaryExpression : + UnaryExpression 1. Let expr be the result of evaluating UnaryExpression. 2. Return ? ToNumber(? GetValue(expr)). NOTE The unary - operator converts its operand to Number type and then negates it. Negating +0 produces -0, and negating -0 produces +0. 12.5.6 Unary + Operator 12.5.6.1 Runtime Semantics: Evaluation 12.5.7 Unary - Operator 12.5.7.1 Runtime Semantics: Evaluation

Slide 40

Slide 40 text

NOTE The unary + operator converts its operand to Number type. UnaryExpression : + UnaryExpression 1. Let expr be the result of evaluating UnaryExpression. 2. Return ? ToNumber(? GetValue(expr)). NOTE The unary - operator converts its operand to Number type and then negates it. Negating +0 produces -0, and negating -0 produces +0. 12.5.6 Unary + Operator 12.5.6.1 Runtime Semantics: Evaluation 12.5.7 Unary - Operator 12.5.7.1 Runtime Semantics: Evaluation

Slide 41

Slide 41 text

਺஋ܕʹม׵͠·͢…

Slide 42

Slide 42 text

The abstract operation ToNumber converts argument to a value of type Number according to Table 10: Table 10: ToNumber Conversions Argument Type Result Unde ined Return NaN. Null Return +0. Boolean If argument is true, return 1. If argument is false, return +0. Number Return argument (no conversion). String See grammar and conversion algorithm below. Symbol Throw a TypeError exception. Object Apply the following steps: 1. Let primValue be ? ToPrimitive(argument, hint Number). 2. Return ? ToNumber(primValue). 7.1.3 ToNumber ( argument )

Slide 43

Slide 43 text

ͭ·Γ console.log(+‘1’) => console.log(1) => 1

Slide 44

Slide 44 text

Ԡ༻

Slide 45

Slide 45 text

Ԡ༻ const n = 12 console.log(n + ‘’) => ’12’ const s = ’12’ console.log(+s) => 12

Slide 46

Slide 46 text

ECMAScriptΛཧղ͢Δͱ

Slide 47

Slide 47 text

JavaScriptͷίʔυͰ͢ [][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]][([][(![]+[])[+[]]+([! []]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]] +([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+ [])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+ []]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+ []+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]((![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(!![]+[]) [!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]+(![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+ []+!+[]+!+[]]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+[]]]+([]+[])[(![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!! []+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(!![]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+ []]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+ []+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+ ([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]()[+!+[] +[!+[]+!+[]]]+(+(!+[]+!+[]+[+[]]))[(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[]) [!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(+![]+([]+[])[([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+ (!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+ []]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+ [])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+ []+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[]) [+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(+![]+[![]]+ ([]+[])[([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[] +!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+ []]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(! []+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[] [[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+ []]]](!+[]+!+[]+[+!+[]])+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[]) [+!+[]]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+([][[]]+[])[+!+[]]+[+!+[]]+[!+[]+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+([]+[]) [(![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]) [+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(!![]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+ []+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+ []+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[]) [+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]()[+!+[]+[!+[]+!+[]]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[] +[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+[]]])()

Slide 48

Slide 48 text

·ͱΊ

Slide 49

Slide 49 text

·ͱΊ • JavaScriptͷܕ͸ECMAScriptͷ࢓༷ॻΛಡΉ • ࢓༷ॻ͸ಠಛ͕ͩঁࢠখֶੜͰ΋ಡΊΔ • Ԡ༻͢ΔͱJSFuckͱݴΘΕΔίʔυ͕ॻ͚Δ