Modern Web Development

Play Modern Web Development

The Discussion

  • User profile image
    Andrew Liang

    Thanks for the great video. Your clarity and elegance matches Scott Hanselman's. :)

    You have mapped your javascript initialization code to your view and controller. However, using this pattern, how would we implement views and javascipt code that are shared by two controllers? We would require two javascript files with virtually the same code. For example, if you have two controllers, Home and Account, and they both have an Index view that require the same javascript code, then two files need to be created that have the same code (ie: Home-Index.js and Account-Index.js) with the exception that they will be created with different object names.

    Most of the javascript code I have written/read, from my experience, are designed to work very closely with the view file and the model that's passed from the controller to the view. In my opinion, the javascript code shouldn't care what controller is used.

  • User profile image

    Thanks Andrew. As far as the controller/view pattern I am using here. The goal of the home-index.js pattern is to quickly implement the initialization for a page. It is common for me to have the same underlying implementation called by both pages. So in your example, I'd simply put the code that two pages share in a JavaScript 'class' or 'module' and call from each initializer.

Add Your 2 Cents