开发者社区> 问答> 正文

js的constructor还是不太理解

var bus = function() {
    this.maxSpeed = 100;
    this.minSpeed = 10;

    this.constructor = function (a, b) {
        this.maxSpeed = a;
        this.minSpeed = b;
    }

    this.show = function () {
        alert('maxSpeed:' + this.maxSpeed + '   this.minSpeed:' + this.minSpeed);
    }
};

var t = new bus(1000,9);
t.show();
document.writeln(t.constructor);

想重写这个方法的构造函数,结果好像没有效果。断点也没有进入constructor 方法内部。

展开
收起
a123456678 2016-03-11 09:36:39 1902 0
1 条回答
写回答
取消 提交回答
  • constructor 这个属性指向的是构造函数,并不是让你在 constructor 这里写一个函数

    2019-07-17 18:58:22
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
JavaScript函数 立即下载
Delivering Javascript to World 立即下载
编程语言如何演化-以JS的private为例 立即下载