รหัสนี้ใช้งานได้แม้ในเบราว์เซอร์ที่แตกต่างกัน:
function fooCheck() {
alert(internalFoo()); // We are using internalFoo() here...
return internalFoo(); // And here, even though it has not been defined...
function internalFoo() { return true; } //...until here!
}
fooCheck();
ฉันไม่สามารถหาข้อมูลอ้างอิงเดียวว่าทำไมมันควรทำงาน ฉันเห็นสิ่งนี้เป็นครั้งแรกในบันทึกการนำเสนอของ John Resig แต่มีการพูดถึงเท่านั้น ไม่มีคำอธิบายใด ๆ ในนั้น
มีคนช่วยสอนฉันได้มั้ย