Solved

JavaScript in Object Oriented Programming

Posted on 2014-03-02
1
497 Views
Last Modified: 2014-03-06
Hello, my JavaScript code is getting messy. I think it would be better organize if I use some Object Oriented techniques.

I also don't know how to combine jQuery event functions with JavaScript functions so everything's neat and easy to read.

How can I accomplish this?

This is a code example:

var ESCAPE_KEY = 27;
var ENTER_KEY = 13;

var user_current_page = 1;
var user_pages_total = 1;

// List users
function load_user() { ... }

// Opens the add form
$(document).on("click", "#btnUserAddForm", function() { ... }

// Adds user
$(document).on("click", "#btnUserAdd", function() { ... }

// Show Edit Form
$(document).on("click", ".btnUserEditForm", function() { ... }

// Saves
$(document).on("click", "#btnUserSave", function() { ... }

// Ask for confirmation on delete
$(document).on("click", ".btnUserDelete", function() { ... }

// Deletes
function user_delete(UsrCod) { ... }

// Cancels add or update
$(document).on("click", "#btnUserCancel", function() { ... }

// Previous page
$(document).on("click", "#btnUserPrevious", function() { ... }

// Next page
$(document).on("click", "#btnUserNext", function() { ... }

// Enter on search field
$(document).on("keyup", "#txtUserSearch", function(event) { ... }

Open in new window


Thanks!
0
Comment
Question by:ivanblue
1 Comment
 
LVL 16

Accepted Solution

by:
hankknight earned 500 total points
ID: 39899003
JavaScript can work well in an object oriented way.  Here is a tutorial:

http://www.scorchsoft.com/blog/how-to-write-object-oriented-javascript/
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
dynamics crm 2011 - Web Resources 1 26
Hovering effect 9 29
angularjs controller not found 1 19
onOpen 14 42
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now