未捕获的TypeError:* .watch不是函数(FireFox除外)

时间:2016-01-10 03:22:36

标签: javascript jquery

我知道有很多关于此的问题,但没人帮忙。

问题在于Watch事件在FireFox中运行良好,但在其他浏览器中不起作用。

我在控制台中收到此错误:

  

未捕获的TypeError:Step.watch不是函数

我需要从中理解什么?手表仅适用于FireFox?



function Step()
{
  this.done = false;
  this.active = false;
};
function StepsControl()
{
  this.steps = new Array();
  this.addListener = function(Step,stepId)
  {
    var self = this;
    Step.watch('done', function (id_, oldval, newval)
    {
      console.log('Step[' + stepId + '].' + id_ + ' changed from ' + oldval + ' to ' + newval);
      if (self.steps[++stepId] !== undefined)
      {
        self.steps[stepId].active = true;
        console.log('Step[' + stepId + '] actived');
      }
      
      return newval;
    });
  };
  this.addStep = function(Step)
  {
    this.steps.push(Step);
    this.addListener(Step,this.steps.length-1);
  };
};

var step1 = new Step();
var step2 = new Step();
var stepsControl = new StepsControl();
stepsControl.addStep(step1);
stepsControl.addStep(step2);
step1.active = true;
step1.done = true;

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:1)

package soniavazquez.anxiety; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toolbar; import com.google.android.gms.appindexing.Action; public class HomeActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home); Button panicAttacks = (Button) findViewById(R.id.button); panicAttacks.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(HomeActivity.this, HelpPanicking.class); startActivity(intent); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home); android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_home, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }); } }); }} 仅在firefox as can be seen when checking MDN

中受支持

答案 1 :(得分:1)

来自Mozilla文档:

  

警告:一般情况下,应尽可能避免使用watch()和unwatch()。这两种方法仅在Gecko中实现,它们主要用于调试使用。此外,使用观察点会对性能产生严重的负面影响,尤其是在全局对象(如窗口)上使用时。您通常可以使用setter和getter或代理。有关详细信息,请参阅浏另外,不要将Object.watch与Object.observe混淆。

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/watch