Solved

JavaScript in Object Oriented Programming

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

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Suggested Courses
Course of the Month11 days, 13 hours left to enroll

623 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