* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
1.8 KiB
1.8 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
id | title | challengeType | videoUrl | forumTopicId | dashedName |
---|---|---|---|---|---|
56533eb9ac21ba0edf2244c7 | 通过点符号访问对象属性 | 1 | https://scrimba.com/c/cGryJs8 | 16164 | accessing-object-properties-with-dot-notation |
--description--
有两种方式访问对象属性,一个是点操作符(.
),一个是中括号操作符([]
)。
当你知道所要读取的属性的名称的时候,使用点操作符。
这是一个使用点操作符读取对象属性的例子:
var myObj = {
prop1: "val1",
prop2: "val2"
};
var prop1val = myObj.prop1; // val1
var prop2val = myObj.prop2; // val2
--instructions--
通过点操作符读取对象testObj
,把hat
的属性值赋给变量hatValue
,把shirt
的属性值赋给shirtValue
。
--hints--
hatValue
应该是一个字符串。
assert(typeof hatValue === 'string');
hatValue
的值应该是"ballcap"
。
assert(hatValue === 'ballcap');
shirtValue
应该是一个字符串。
assert(typeof shirtValue === 'string');
shirtValue
的值应该是"jersey"
。
assert(shirtValue === 'jersey');
你应该使用点操作符两次。
assert(code.match(/testObj\.\w+/g).length > 1);
--seed--
--after-user-code--
(function(a,b) { return "hatValue = '" + a + "', shirtValue = '" + b + "'"; })(hatValue,shirtValue);
--seed-contents--
// Setup
var testObj = {
"hat": "ballcap",
"shirt": "jersey",
"shoes": "cleats"
};
// Only change code below this line
var hatValue = testObj; // Change this line
var shirtValue = testObj; // Change this line
--solutions--
var testObj = {
"hat": "ballcap",
"shirt": "jersey",
"shoes": "cleats"
};
var hatValue = testObj.hat;
var shirtValue = testObj.shirt;