2020年7月8日 星期三

Message Mixer

先建立一個有名子的空物件,把我想打包的函數都作為他的性質存起來。
如果函數都是 function Name(){*}這副德行,我該怎麼做 ?
我的作法是就是 Name: function(){*},看過Hint就知道我錯了。

函數當成Object.PropertyName ( === function's Name) = Anonymous Function
MessageMixer = {};
Message.Name = function(){*}

sentence.split(" ").join(character + " ")
const character = '&';
const sentence = "My name is Chung Hao Yang.";
sentence.split(" ") 
Array ["My", "name", "is", "Chung", "Hao", "Yang."]
按照空白,拆解 string 成 array

.join() 回傳 拼接成的字串,.join(character + " ") = "&_",底線代表空白。

console.log(sentence.split(" ").join(character + " "));
=> "My&_name&_ is&_ Chung&_Hao&_Yang."

module.exports 和 export default 之間的差異
module.exports = ObjectName;
let VariableName = require('Path')

export default ObjectName;
import ObjectName from 'Path'

Node.js 支援 module.exports 和 require(),ES6 支援 export default / import  from,後者可讀性及彈性高。


現在遇到一個問題
let availableAirplanes = [ {name: 'AeroJet', fuelCapacity: 800, availableStaff: ['pilots', 'flightAttendants', 'engineers', 'medicalAssistance', 'sensorOperators'], maxSpeed: 1200, minSpeed: 300 }, {name: 'SkyJet', fuelCapacity: 500, availableStaff: ['pilots', 'flightAttendants'], maxSpeed: 800, minSpeed: 200 } ]; function displayFuelCapacity() { availableAirplanes.forEach(function(element) { console.log('Fuel Capacity of ' + element.name + ': ' + element.fuelCapacity); }); }
element.name 為什麼不能改成 element["name"] ?
可以,是我剛剛打錯成 element.[name] ,正確是 element["name"]

displayFuelCapacity();

================================

console.log(MessageMixer.palindrome());
  console.log(MessageMixer.pigLatin()); //我怎麼知道我要傳什麼參數




沒有留言:

張貼留言