Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-01-2013, 09:18 AM   PM User | #1
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,177
Thanks: 214
Thanked 31 Times in 30 Posts
durangod is on a distinguished road
function not validating due to &&

Trying to get this to pass W3C validation.

The problem is the two & it does not like them and i tried
&& but then the code bombs.


PHP Code:

function bundleFunction(contextfuncargs
{
  
context context || null;
  if(
typeof func == "string" && context)
    
func context[func];
  if(!
args)
    
args = [];
  else if(!(
args instanceof Array))
    
args = [args];
  return function() {
    return 
func.apply(contextargs);
  }
}
//close function bundleFunction 
Any suggestions thanks

Last edited by durangod; 01-01-2013 at 04:07 PM..
durangod is offline   Reply With Quote
Old 01-01-2013, 09:36 AM   PM User | #2
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,177
Thanks: 214
Thanked 31 Times in 30 Posts
durangod is on a distinguished road
Well i did get it to validate but i had to totally remove the && entirely. I tried wrapping in () as well as other attemps but encase them but no good. I have never seen that happen before.

So this is the new code, it does seem to work but hope i didnt mess it up lol

PHP Code:

function bundleFunction(contextfuncargs
{
  
context context || null;
  if(
typeof func == "string")
  {
    if(
context)
    {
    
func context[func];
    }
//close if
  
}//close if

  
if(!args)
  {
   
args = [];
     }else if(!(
args instanceof Array))
       {
      
args = [args];
       }

    return function() 
     {
     return 
func.apply(contextargs);
     }

}
//close function bundleFunction 
durangod is offline   Reply With Quote
Old 01-01-2013, 09:51 AM   PM User | #3
vwphillips
Senior Coder

 
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,356
Thanks: 3
Thanked 458 Times in 445 Posts
vwphillips is a jewel in the roughvwphillips is a jewel in the roughvwphillips is a jewel in the rough
I validate your original using http://validator.w3.org/check and it was fine

What DOC type are you using?
__________________
Vic

God Loves You and will never love you less.

http://www.vicsjavascripts.org.uk/

If my post has been useful please donate to http://www.operationsmile.org.uk/
vwphillips is offline   Reply With Quote
Old 01-01-2013, 10:27 AM   PM User | #4
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,614
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
Yeah, sounds like you’re using XHTML. In that case you need to declare your JS as character data (CDATA), otherwise the parser thinks it’s still HTML.
Code:
<script type="text/javascript">
// <![CDATA[
… your code here …
// ]]>
</script>
The best, however, is to have unobtrusive JS in a separate file which you just reference in the head using the src attribute.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Users who have thanked VIPStephan for this post:
durangod (01-01-2013)
Old 01-01-2013, 04:04 PM   PM User | #5
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,177
Thanks: 214
Thanked 31 Times in 30 Posts
durangod is on a distinguished road
Quote:
Originally Posted by vwphillips View Post
I validate your original using http://validator.w3.org/check and it was fine

What DOC type are you using?
Code:
<?xml version="1.0" encoding="iso-8859-1"?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="EN">
durangod is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:18 PM.


Advertisement
Log in to turn off these ads.