时间:2021-07-01 10:21:17 帮助过:36人阅读
// If the color is red, turn it green if (color.is_red()) { color.turn_green(); }二、要注释说明推理和历史(√)
/* The API currently returns an array of items even though that will change in an upcoming ticket. Therefore, be sure to change the loop style here so that we properly iterate over an object */ var api_result = {items: ["one", "two"]}, items = api_result.items, num_items = items.length; for(var x = 0; x < num_items; x++) { ... }三、同一行的注释不要写得很长(×)
function Person(name) { this.name = name; this.first_name = name.split(" ")[0]; // This is just a shot in the dark here. If we can extract the first name, let's do it }四、要把长注释放在逻辑上面,短注释放在后面(√)
if (person.age < 21) { person.can_drink = false; // 21 drinking age /* Fees are given to those under 25, but only in some states. */ person.has_car_rental_fee = function(state) { if (state === "MI") { return true; } }; }五、不要为了注释而添加不必要的注释(×)
if (person.age >= 21) { person.can_drink = true; // A person can drink at 21 person.can_smoke = true; // A person can smoke at 18 person.can_wed = true; // A person can get married at 18 person.can_see_all_movies = true; // A person can see all movies at 17 //I hate babies and children and all things pure because I comment too much }六、注释要拼写正确(√)