JS:EcmaScript6如何将不同数量的参数传递给扩展类

时间:2016-11-10 22:33:41

标签: javascript ecmascript-6

我班上有点问题。它必须非常简单,但我无法找到解决方案。类Cuboid运行良好,但类Cube不是很好,我认为我以错误的方式使用了super方法。

请给我一点提示。提前谢谢。

class Cuboid {
  constructor(length, width, height) {
    this.length = length;
    this.width = width;
    this.height = height;
  }
  get surfaceArea() {
    return (this.length * this.width + this.length * this.height + this.height * this.width) * 2;
  }
  get volume() {
    return this.length * this.width * this.height;
  }
}
class Cube extends Cuboid {
  constructor(length) {
    super(length);
    this.height = length;
  }
}

伙计们,你为什么要投票我的问题?这不是很好......

1 个答案:

答案 0 :(得分:3)

正如我所说Cube是Cuboid,所有3维相等。所以有两种选择:

1

public void MakePost(final PostModel model){
    new AsyncTask<Void,Void,String>(){
        @Override
        protected void onPreExecute() {
            super.onPreExecute();

            progressDialog = new ProgressDialog(SignUpActivity.this,R.style.Theme_MyDialog);
            progressDialog.setMessage("Sending....");
            progressDialog.setCancelable(false);
            progressDialog.setCanceledOnTouchOutside(false);
            progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            progressDialog.show();
        }
        @Override
        protected String doInBackground(Void... params) {
            try{
                PostBase postBase = new PostBase();
                statusCode = postBase.POST(model);
                if(statusCode == 201){
                    return "OK";
                }
                if(statusCode == 409){
                    return "Conflict";
                }
                else {
                    return "ERROR";
                }
            }catch (IOException e){
                e.printStackTrace();
                return "ERROR";
            }
        }
        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            switch (s) {
                case "OK":
                    progressDialog.dismiss();
                    AlertDialog.Builder builder1 = new AlertDialog.Builder(SignUpActivity.this);
                    builder1.setTitle("Gone");
                    builder1.setMessage("Fine");
                    builder1.setCancelable(true);

                    builder1.setPositiveButton(
                            "ok",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {
                                    dialog.cancel();
                                }
                            });

                    AlertDialog alert11 = builder1.create();
                    alert11.show();
                    //finish();
                    break;
                case "Conflict":
                    progressDialog.dismiss();
                    new DialogMessage(SignUpActivity.this, "already exist");
                    break;
                default:
                    progressDialog.dismiss();
                    new DialogMessage(SignUpActivity.this, "something went wrong");
                    break;
            }
        }
    }.execute();
}

2

class Cube extends Cuboid {
  constructor(length) {
    super(length, length, length);
  }
}