gpt4 book ai didi

javascript - 玩javascript函数 - 具有命名和克隆的对象

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:25:18 26 4
gpt4 key购买 nike

我通过 stackoverflow 偶然发现了这个,这是一个很好的资源,并且有很多关于这个的对话,但我仍然感到困惑,为什么某些东西不起作用?

我在大学里学过c++,对指针内存犹新

http://www.permadi.com/tutorial/jsFunc/index2.html

我的问题是代码中某些部分不起作用

function theAdd(a, b){    
return a*b;
}

//creating a copy of the function
var add3 = new theAdd();

add3.name = 'nameProperty';
//alert( add3(1,2)) //why doesn't this work?
alert(theAdd(5,5) + " " + theAdd.name);


function Ball() {
return 'balltext';
}
var ball0=new Ball(); // ball0 now points to a new object

alert( Ball() ); // this works
alert( ball0() ); // why doesn't this work? shouldn't it return balltext?

最佳答案

因为 ball0 是一个对象,你不能像函数一样使用它

请检查此以查看 how new works

关于javascript - 玩javascript函数 - 具有命名和克隆的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18705831/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com