开发者

Same code for client and server

Is it feasible to have parts of the code shared between webapp's client and server? Assuming 开发者_Go百科I use a javascript-based server, I hope I could have at least form verification code and parts of logic shared.

I worry about incompatibilities between javascript engines, though.


If your code runs on Chrome (V8), it will also run under Node.js (V8) which today, is the #1 choice for server side JavaScript.

Of course you need to make sure that you don't use any Chrome specific stuff, but the same hold true for things that only work Firefox (like noSuchMethod) etc.

But I can't think of any particular things when it comes to form validation that would break cross engine compatibility.


http://jaxer.org/ has some really nice looking examples for sharing code between client and server, as well as manipulating the DOM in both locations. However, this project looks like it may have been abandoned by its creator. Just posting the link because the design concepts might be useful to you when trying to share validation code in both locations.


Engine incompatibility should not extend to data-validation, it should be limited to DOM interaction.

If your javascript engines are so weirdly different that they treat strings and integers and whatnot differently -- stop using them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜