2
Express.jsアプリケーションのJavaScriptモデルオブジェクトに文字列の配列であるプロパティを正常に追加するには、以下のコードを変更する必要があります?AppUser
コードは、/app/models
directory of this GitHub linkの新しいappuser.js
ファイルに格納されています。ここでこのExpress.jsモデルクラスに配列プロパティを追加
はこのOPは書く方法を尋ねる配列、のためのゲッターとセッターのためのプレースホルダを含むAppUser
クラスのコードです:
var method = AppUser.prototype;
function AppUser(name) {
this._name = name;
}
method.getName = function() {
return this._name;
};
//scopes
method.getScopes = function() {
//return the array of scope string values
};
method.setScopes = function(scopes) {
//set the new scopes array to be the scopes array for the AppUser instance
//if the AppUser instance already has a scopes array, delete it first
};
method.addScope = function(scope) {
//check to see if the value is already in the array
//if not, then add new scope value to array
};
method.removeScope = function(scope) {
//loop through array, and remove the value when it is found
}
module.exports = AppUser;
コーディングレベルを向上させたい場合は、試してみる必要があります。それでも問題が解決しない場合は、コードを投稿してください。さもなければ、あなたは宿題をしたいと思うかもしれません。 –
「厳密に使う」ことを忘れないでください。それは私のplateform Express "version": "4.13.3"で動作します。しかし、それはどのようにこのクラスを明示的に使用するかによって決まります... –
は()のために修正されました。しかし、 "厳密な使用"または "厳格な使用"は同じです –