Solved

JavaScript in Object Oriented Programming

Posted on 2014-03-02
1
512 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
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)

710 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