Aug 01, 2011, 7:48 AM
Javascript coding patterns / best practise
Hi,
I've been using Ext.NET for a few months now, and I'm finding that my javascript files are starting to get heavy and quite brittle, so I was thinking about refactoring them a bit. I've been looking at some of the new js frameworks / libs out there like backbone.js and knockout.js, and wondered if they could be useful in the context of the UI-oriented JS that we use in ext.net...
Current issues I have with my JS files:
So, I was wondering if there are any best practice or thoughts on this. In hindsight, I think a better approach would be to separate out all of the code that gets data from UI elements into a separate class that populates a sort of view-model, and then use that view model in my other classes which perform operations on that code - this would help with testability too.
Any thoughts/ideas welcome!
(Please feel free to move to a more appropriate area in the forum if necessary)
Thanks
Matt
I've been using Ext.NET for a few months now, and I'm finding that my javascript files are starting to get heavy and quite brittle, so I was thinking about refactoring them a bit. I've been looking at some of the new js frameworks / libs out there like backbone.js and knockout.js, and wondered if they could be useful in the context of the UI-oriented JS that we use in ext.net...
Current issues I have with my JS files:
- No seperation of concerns - a few JS classes containing code for UI, data operations, etc
- Cunfusion around "this" - since ExtJS usually changes the context of this when an event calls a method in my class, it prevents me from being able to call "this.otherMethod" from my classes
- Tight coupling - no testability
So, I was wondering if there are any best practice or thoughts on this. In hindsight, I think a better approach would be to separate out all of the code that gets data from UI elements into a separate class that populates a sort of view-model, and then use that view model in my other classes which perform operations on that code - this would help with testability too.
Any thoughts/ideas welcome!
(Please feel free to move to a more appropriate area in the forum if necessary)
Thanks
Matt