Hello, everyone. I am Karsong.
Spread syntax should be used frequently in business, such as expanding arrays:
function sum(x, y, z) {
return x + y + z;
}
const numbers = [1.2.3];
/ / 6
console.log(sum(... numbers));Copy the code
Clone object:
constclone = { ... obj };Copy the code
But have you ever seen something like this:
This article will discuss the causes of the above situation.
Welcome to join the Human high quality front-end framework research group, Band fly
Expand the action of the operator on a string
Iterable is a type added to ES2015. The expansion operator can be applied to iterable to expand it to zero or more arguments. The common types, Array and String, are iterable.
Iterable can use for.. Of syntax traversal, for example:
for (let i of 'abc') {
console.log(i)
}
// a
// b
// c
Copy the code
It makes sense that Array belongs to Iterable, but why does String belong to Iterable?
This is because prior to ES2015, String basically implemented all elements of Array traversal, such as:
-
Has a.length property
-
A character that can be accessed at an index position by subscript
We won’t discuss whether this implementation is correct, except to say that for traversal, String is similar to the Array experience.
So in ES2015, when Array as iterable supports for… Of traversals, empirically, strings need to support the same syntax.
The result of expanding a family of three with the expansion operator:
Use for… Of traverses to see the corresponding Unicode character:
So what’s so special about a family of three as an emoji?
Emoji Sequence
This combination of multiple emojis is called emoji Sequence, which makes use of the feature that text can be combined to form.
Thai, for example, is a script that can be combined to form.
ผ ั ด ผ ั ด accountancy accountancy accountancy accountancy accountancy accountancy accountancy accountancy accountancy You will notice that there is a cap above the character.
In addition, some Thai characters have shoes, such as dried dried dried fruit.
Or have both a hat and shoes, such as Dried dried fruit.
In the Thai input method, the user enters the basic character, hat, shoe, and then enters the end character to form a complete character.
ZWJ: ZWJ: ZWJ: ZWJ: ZWJ: ZWJ: ZWJ: ZWJ: ZWJ: ZWJ
From the above for… The result of the of traversal shows that the zero-width character is \u200D. It is usually used in typesetting. But Emoji Sequence took him as glue between emojis.
In other words, you can use \u200D to combine multiple emojis into an emoji Sequence.
For example, father, mother, little boy can be grouped into a family of three:
Of course, so can little girls:
A little girl combined with a cap to form a little girl wearing a cap:
conclusion
Once you know how to combine them, you can combine existing emoji sequences to create new ones.
Two dads with kids, two moms with kids, you can try it