gpt4 book ai didi

javascript - 使用javascript OOP中的方法动态获取属性

转载 作者:行者123 更新时间:2023-11-30 18:10:25 24 4
gpt4 key购买 nike

<分区>

如果我创建一个类 SONG(),并定义许多属性,我如何创建一个方法来使用传递的参数并获取该属性?

function SONG(i) {

/* properties */
this.title = results.title[i];
this.artist = results.artist[i];
this.album = results.album[i];
this.info = results.info[i];

/* methods */
this.getstuff = function(stuff){
console.log(this.stuff); // doesn't work
}
}

var song1 = new SONG(1);

song1.getstuff(title);
// how can I have this dynamically 'get' the property passed through as an argument?

非常感谢任何帮助或建议!

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