雅虎香港 搜尋

搜尋結果

  1. A JavaScript function is a block of code designed to perform a particular task. A JavaScript function is executed when "something" invokes it (calls it). Example. // Function to compute the product of p1 and p2. function myFunction (p1, p2) { return p1 * p2; } Try it Yourself » JavaScript Function Syntax.

  2. 2023年10月4日 · Functions are one of the fundamental building blocks in JavaScript. A function in JavaScript is similar to a procedure—a set of statements that performs a task or calculates a value, but for a procedure to qualify as a function, it should take some input and return

  3. 首先我们可以先了解 JavaScript 函数 和 JavaScript 作用域 。 更多详细的内容可以查看 函数定义 , 参数 , 调用 和 闭包 。 提示: 使用 return 语句来返回函数的值。 浏览器支持. 语法. function functionName ( parameters) { 执行的代码. } 参数值. 技术细节. 更多实例. 实例. 返回 PI 值: function myFunction () { return Math.PI; } 输出结果: 3.141592653589793. 尝试一下 » 实例. 返回 a 乘于 b 的值:

  4. prototype. 在使用 function 作为构造函数与 new 运算符一起使用时,用作新对象的原型。 实例方法. Function.prototype.apply() 使用给定的 this 值和可选的参数数组(或 类数组对象 )作为参数来调用一个函数。 Function.prototype.bind() 创建一个新的函数,在调用时,其 this 关键字被设置为提供的值,可选地在调用新函数时在提供的参数之前加上一系列给定的参数。 Function.prototype.call() 使用给定的 this 值和可选参数调用一个函数。 Function.prototype.toString() 返回表示函数源代码的字符串。

  5. 函式. « 前頁. 次頁 » 函式是構成 javascript 的基本要素之一。 一個函式本身就是一段 JavaScript 程序—包含用於執行某一個任務或計算的語法。 要呼叫某一個函式之前,你必需先在這個函式欲執行的 scope 中定義它。 定義函式. 一個函式的定義由一系列的函式關鍵詞組成, 依次為: 函式的名稱。 包圍在括號 ()中,並由逗號區隔的一個函式參數列表。 包圍在大括號 {}中,用於定義函式功能的一些 JavaScript 語句。 例如,以下的程式碼定義了一個名為 square 的簡單函式: js. function square(number) { return number * number; } 函式 square 有一個參數,叫作 number。

  6. 其他人也問了

  7. 函數 (function) 用來將會重複使用的程式碼封裝在一起,方便重複執行。 函數宣告 (Function declaration) 先來看看函數的宣告語法: function functionName(parameter1, parameter2, ...) // statements // return value; . } 我們用 function 這個關鍵字來宣告一個函數. 緊接著是指定這個函數的名稱 functionName. 然後小括號 () 裡面指定這個函數的參數,可以用逗點 , 分隔多個參數. 最後在大括號 {} 裡面則是你想封裝在這個 function 的程式碼. 一個函數可以有返回值,使用 return 關鍵字來返回一個值.

  8. 2022年10月14日 · A function can return a value back into the calling code as the result. The simplest example would be a function that sums two values: function sum(a, b) { return a + b; } let result = sum(1, 2); alert( result ); // 3. The directive return can be in any place of the function.

  1. 其他人也搜尋了