Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

JavaScript in Object Oriented Programming

Posted on 2014-03-02
1
Medium Priority
?
523 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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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)

722 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