如何在JavaScript中使用Structs?
要在JavaScript中使用结构,可以尝试运行以下代码–
示例
<!DOCTYPE html> <html> <body> <script> function displayStruct(str) { var str = str.split(' '); var count = str.length; function constructor() { for (var i = 0; i < count; i++) { this[str[i]] = arguments[i]; } } return constructor; } var Item = displayStruct("player country"); var res = new Item('Sachin', 'India'); alert("Country: "+res.country); </script> </body> </html>