LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-15-2009, 08:31 PM   #1
jchambers
Member
 
Registered: Aug 2007
Location: California
Distribution: Debian
Posts: 127

Rep: Reputation: 15
javascript - class / function in function


Hello all.

I am not sure what the benefit will be to this besides keeping is all together..?
My goal is to create a class for functions I wrote.
The functions all work together for one purpose so I would like them packaged if possible.
The only classes I know are in php so this seems a bit different to me.


I would have thought this would work.?
Code:
function myClass()
{
	var a = "HELLO";
	
	function init()
	{
		alert("MSG: "+ this.a);
	}
	
}

myClass.init;

Can someone please give me a tip and maybe wirte a simple example?

Thank you,
Jon
 
Old 06-15-2009, 09:35 PM   #2
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
I can't exactly remember where I saw it, but nested functions in PHP, in short, DON'T! If I remember correctly, it has something to do with PHP being a script language, as opposed to a compiled language.

jlinkels
 
Old 06-15-2009, 09:40 PM   #3
grizly
Member
 
Registered: Nov 2006
Location: Melbourne Australia
Distribution: Centos, RHEL, Debian, Ubuntu, Mint
Posts: 128

Rep: Reputation: 16
Well, he's asking about JS.. not PHP.

some basic info: http://webdevelopersjournal.com/arti...js_begin3.html
 
Old 06-15-2009, 10:33 PM   #4
jchambers
Member
 
Registered: Aug 2007
Location: California
Distribution: Debian
Posts: 127

Original Poster
Rep: Reputation: 15
Thank you both for the reply.


jlinkels - Yes thanks, I know not do that in php, but I did not see alternative in javascript.

grizly - I skimmed through it before. I will give it a good read.


Now I see am going down the wrong path. Nesting functions I see is not the answer. It works with separate functions (non nested) and I will leave it at that for now.

Jon
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling a function in javascript mohtasham1983 Programming 4 03-04-2008 04:13 PM
help with javascript function paul_mat Programming 3 02-15-2006 12:48 PM
how pass a class to a function aditya1 Programming 2 03-08-2005 09:02 PM
function prototypes in template class' (c++) qwijibow Programming 4 12-13-2004 09:34 AM
Function Definitoin Outside Templatized Class ashwinipahuja Programming 1 06-15-2004 10:53 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration