Basic View coding rules

Now, it is time to start coding the first View component. To help us through the process, we are going to lay two basic rules for View coding happiness:

  • The View should encapsulate a DOM element
  • Integrate Views with observers

So, let's see how they work individually.

The View should encapsulate a DOM element

As mentioned earlier, a View is the behavior associated with a DOM element, so it makes sense to have this element related to the View. A good pattern is to pass a CSS selector in the View instantiation that indicates the element to which it should refer. Here is the spec for the NewInvestmentView component:

describe("NewInvestmentView", function() {
  var view; beforeEach(function() { loadFixtures('NewInvestmentView.html'); ...

Get Jasmine JavaScript Testing - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.