创建两个对象独立运行
var PlayTrace = function (interVal,name) { this.interVal = interVal; this.playName = name; }; PlayTrace.prototype = function () { startPlay = function (beginVal) { if (this.playInterVal) { clearInterval(this.playInterVal); } this.playInterVal = window.setInterval(function (name) { console.log(name + "," + beginVal); beginVal++; }, this.interVal, this.playName); } return { startPlay: startPlay } }(); var play1 = new PlayTrace(1000, "play1"); play1.startPlay(1); var play2 = new PlayTrace(2000,"play2"); play2.startPlay(100);