We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
class Chameleon { static colorChange(newColor) { this.newColor = newColor return this.newColor } constructor({newColor = 'green'} = {}) { this.newColor = newColor } } const freddie = new Chameleon({newColor: 'purple'}) freddie.colorChange('orange') // TypeError // colorChange是一个静态方法。静态方法被设计为只能被创建他们的构造器使用(也就是Chameleon),并且不能传递给实例。因为freddie是一个实例,静态方法不能被实例使用,因此抛出TypeError错误
问题出处:JavaScript 进阶问题列表-问题8
The text was updated successfully, but these errors were encountered:
No branches or pull requests
class Chameleon {
static colorChange(newColor) {
this.newColor = newColor
return this.newColor
}
constructor({newColor = 'green'} = {}) {
this.newColor = newColor
}
}
const freddie = new Chameleon({newColor: 'purple'})
freddie.colorChange('orange')
// TypeError
// colorChange是一个静态方法。静态方法被设计为只能被创建他们的构造器使用(也就是Chameleon),并且不能传递给实例。因为freddie是一个实例,静态方法不能被实例使用,因此抛出TypeError错误
The text was updated successfully, but these errors were encountered: