JSFiddle - React, Tailwind, and code Playground
by yi hom
JavaScript
function makePerson(first, last) {//建立一個物件:人名,包含first和last
return {
first: first,
last: last
};
}
function personFullName(person) {//在其他的函式中可以分別使用
return person.first + ' ' + person.last;
}
function personFullNameReversed(person) {
return person.last + ', ' + person.first;
}
s = makePerson("Simon", "Willison");
a = personFullName(s);
b = personFullNameReversed(s);
document.write(a+"<br>"+b+"<br><br>");
//範例二
function makepc(cpu, mb) {//建立一個物件:電腦,包含cpu和mb
return {
cpu: cpu,
mb: mb
};
}
function pc(pc) {
return pc.cpu + ', ' + pc.mb;
}
x = makepc("intel", "asus");
y = pc(x);
document.write(y+"<br>");