gpt4 book ai didi

javascript - 在 javascript 中创建一个带有方法的类

转载 作者:行者123 更新时间:2023-12-01 01:12:42 25 4
gpt4 key购买 nike

我已经为此工作了好几天,但到目前为止还没有成功。每次我运行这段代码时,我都会被告知它应该是 true (或 false),具体取决于我如何执行该函数。

function ClassTwo(name, pw, mail){
// Exercise Two: Now that you have created your own class,
// you will create a class with a method on it.
// In this class create 4 properties: username, password, email, and checkPassword.
// Set the value of username to name,
// Set the value of password to pw,
// Set the value of email to mail
// Set the value of checkPassword to a function.
// The checkPassword function takes a string as it's only argument.
// Using the 'this' keyword check to see if the password on the class is the same as
// the string being passed in as the parameter. Return true or false.

this.username = name,
this.password = pw,
this.email = mail
this.checkPassword = function checkPassword() {
return this.password
}

}

最佳答案

您缺少 checkPassword 函数的 tested_pw 参数

function ClassTwo(name, pw, mail){
// Exercise Two: Now that you have created your own class,
// you will create a class with a method on it.
// In this class create 4 properties: username, password, email, and checkPassword.
// Set the value of username to name,
// Set the value of password to pw,
// Set the value of email to mail
// Set the value of checkPassword to a function.
// The checkPassword function takes a string as it's only argument.
// Using the 'this' keyword check to see if the password on the class is the same as
// the string being passed in as the parameter. Return true or false.

this.username = name,
this.password = pw,
this.email = mail
this.checkPassword = function checkPassword(tested_pw) {
return this.password === tested_pw
}

}

关于javascript - 在 javascript 中创建一个带有方法的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55029383/

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