Bryntum Quiz 10

by Alexander Novikov

HTML

<script src="https://getfirebug.com/firebug-lite-debug.js"></script>
<link rel="stylesheet" href="http://cdn.sencha.io/ext-4.2.0-gpl/resources/css/ext-all.css">
<script src="http://cdn.sencha.io/ext-4.2.0-gpl/ext-all.js"></script>
<div id="myDiv" style="background-color: red;">myDiv</div>

JavaScript

/*
10. What is wrong with the following Ext JS snippet:

  var myEl = Ext.fly(‘myDiv’);
  myEl.highlight();    // Show user where the element is
  myEl.setHeight(200);

  // Some other code 
  // …
  var panel = new Ext.Panel();
  panel.render(document.body);

  myEl.setWidth(200);
  
*/

var myEl = Ext.fly('myDiv');
myEl.highlight();    // Show user where the element is
myEl.setHeight(200);
// Some other code
var panel = new Ext.Panel();
panel.render(document.body);
/*
http://docs.sencha.com/extjs/4.2.2/#!/api/Ext-method-fly
Because it is a singleton, this Flyweight does not have an ID, and must be used and discarded in a single line. You may not keep and use the reference to this singleton over multiple lines because methods that you call may themselves make use of fly and may change the DOM element to which the instance refers.
*/
var myEl = Ext.fly('myDiv'); //<--- this line added
myEl.setWidth(200);