使用原型函数name.argument的JavaScript函数调用是如何工作的?
在以下程序中,使用原型函数name.argument的JavaScript函数调用如何工作使用原型函数name.argument的JavaScript函数调用是如何工作的?,javascript,Javascript,在以下程序中,使用原型函数name.argument的JavaScript函数调用如何工作 function getLAdd() { // this sets all the variables containing positions of ball and bar with their respective ids. var ladd = 0; var pball = $("#ball"); var pbar = $("#bar"); va
function getLAdd() {
// this sets all the variables containing positions of ball and bar with their respective ids.
var ladd = 0;
var pball = $("#ball");
var pbar = $("#bar");
var bar_position = pbar.position();
var ball_position = pball.position();
if (ball_position.top >= window.innerHeight - 100) {
if (ball_position.left - 10 >= bar_position.left && ball_position.left - 10 <= bar_position.left + 100) {
ladd = -2;
}
if (ball_position.left + 10 <= bar_position.left + 200 && ball_position.left + 10 >= bar_position.left + 100) {
ladd = 2;
}
}
// how does getLAdd.ladd work ? Is this a type of dynamic call ?
if (ladd == 0) {
ladd = getLAdd.ladd;
}
if (ball_position.left <= 15 || ball_position.left >= window.innerWidth - 40)
ladd = -ladd;
getLAdd.ladd = ladd;
return ladd;
}
函数getLAdd(){
//这将设置包含球和杆位置的所有变量及其各自的ID。
var-ladd=0;
var pball=$(“球”);
var pbar=$(“#巴”);
变量bar_position=pbar.position();
var ball_position=pball.position();
如果(ball_position.top>=window.innerHeight-100){
如果JavaScript中的(ball_position.left-10>=bar_position.left&&ball_position.left-10函数是对象,那么您可以向它们添加属性 在此代码中,名为
ladd
的属性已添加到getLAdd
函数中,并在此行检索:
ladd = getLAdd.ladd;
getLAdd.ladd = ladd;
并正在这一行进行更新:
ladd = getLAdd.ladd;
getLAdd.ladd = ladd;
您可以对任何函数执行相同的操作
function f() {
// get the property
console.log(f.foo); // bar
}
// add a property to the function object
f.foo = "bar";
// get the property
console.log(f.foo); // bar
// call the function
f();