使用 rest 从构造函数向下传递到方法中的 class 访问参数
Accessing arguments from a class passed down from the constructor into a method using rest
我试图通过构造函数将每个参数传递给方法,该方法又对值进行加密。但是,该方法并未读取参数中的值。
拜托,我做错了什么?
class Add {
constructor(...words) {
this.words = words;
}
print(words){
words = [words];
let output = "$"
console.log(words)
for(let word of words){
output += word +"$"
}
return output
}
}
var x = new Add("I", "Love","you");
var y = new Add("this", "is", "awesome");
x.print()
z.print()
你拼错了构造函数,而且如果你在构造函数内部给 this
赋值,那么你也可以在 this
上用其他方法访问它。
class Add {
constructor(...words) {
this.words = words;
}
print() {
let output = "$"
for (let word of this.words) {
output += word + "$"
}
return output
}
}
var x = new Add("I", "Love", "you");
console.log(x.print())
我试图通过构造函数将每个参数传递给方法,该方法又对值进行加密。但是,该方法并未读取参数中的值。
拜托,我做错了什么?
class Add {
constructor(...words) {
this.words = words;
}
print(words){
words = [words];
let output = "$"
console.log(words)
for(let word of words){
output += word +"$"
}
return output
}
}
var x = new Add("I", "Love","you");
var y = new Add("this", "is", "awesome");
x.print()
z.print()
你拼错了构造函数,而且如果你在构造函数内部给 this
赋值,那么你也可以在 this
上用其他方法访问它。
class Add {
constructor(...words) {
this.words = words;
}
print() {
let output = "$"
for (let word of this.words) {
output += word + "$"
}
return output
}
}
var x = new Add("I", "Love", "you");
console.log(x.print())