Solved

JavaScript in Object Oriented Programming

Posted on 2014-03-02
1
500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

932 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

15 Experts available now in Live!

Get 1:1 Help Now