作者B9 (叶酸酸♪)
看板Ajax
标题Re: [ js ] 请问 new 的语法
时间Tue Mar 31 22:39:38 2009
※ 引述《HuangJC (吹笛牧童)》之铭言:
: t = new Array(); //这样可以建立一个阵列
: t = Array(); //这样一样可以建立阵列,有差吗?
"The new operator must be followed by a function invocation. It creates a new
object, with no properties and then invokes the function, passing the new
object as the value of the this keyword."
from: JavaScript: The Definitive Guide, 5th Edition, 9.1. Constructors
上面是对 new 的解释。
不过我没有在这本书看过 t = Array() 的看法,在我来看的话,我会看成是一个
function,并将 return value assign 给 t。
可以用 for ... in statement 测试,只要 a 的 attributes b 都有,
而且 b 的 attributes a 也都有,就可以当作都是“一样”的 object 了。
--
First they gossiped...
They gossiped first about Proscar, and I didn't speak up because I wasn't him.
Then they gossiped about SkyRS, and I didn't speak up because I wasn't him.
Then they gossiped about hugo811, and I didn't speak up because I wasn't her.
Then they gossiped about B9, and I didn't speak up because I was a villager;
Then they gossiped about me, and by that time no one was left to speak up.
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 203.70.51.201