[RFC|Merged] Javascript Coding Style

These requests for comments/change have lead to an implemented feature that has been successfully merged into the 3.1/Ascraeus branch. Everything listed in this forum will be available in phpBB 3.1.
_hsr
Registered User
Posts: 42
Joined: Mon Mar 26, 2012 7:06 am

[RFC|Merged] Javascript Coding Style

Post by _hsr »

Code: Select all

phpbb.attachment_lightbox() {
	this.init = function() {
		if(this.sources === undefined) {
			return this.addSources();
		}
		else {
			return this.enable();
		}
	}
}
This is a piece of code I'm working on right now, and I'd like to suggest the following changes:

Code: Select all

phpbb.add_ajax_callback = function(id, callback)
{
	if (typeof callback === 'function')
	{
		phpbb.ajax_callbacks[id] = callback;
	}
	return this;
}
be changed to

Code: Select all

phpbb.add_ajax_callback = function (id, callback) {
	if (typeof callback === 'function') {
		phpbb.ajax_callbacks[id] = callback;
	}
	return this;
}
Ticket
http://tracker.phpbb.com/browse/PHPBB3-10855

Patch
https://github.com/phpbb/phpbb3/pull/779
There is a text here !

User avatar
callumacrae
Former Team Member
Posts: 1046
Joined: Tue Apr 27, 2010 9:37 am
Location: England
Contact:

Re: [RFC|Accepted] Coding Guideline Modifications

Post by callumacrae »

Your second example is wrong. It should be:

Code: Select all

phpbb.add_ajax_callback = function(id, callback) {
   if (typeof callback === 'function')
   {
      phpbb.ajax_callbacks[id] = callback;
   }
   return this;
}
Parentheses go on the same line with function expressions (but not function declarations) and objects.

I've proposed having parentheses on their own line in the 4.0 Coding Guidelines topic, feel free to go +1 it. It won't be done in 3.x.
Made by developers, for developers!
My blog

_hsr
Registered User
Posts: 42
Joined: Mon Mar 26, 2012 7:06 am

Re: [RFC|Accepted] Coding Guideline Modifications

Post by _hsr »

Parentheses?
Or do you mean curly braces?

And if you are saying the second one is wrong, as in this one:

Code: Select all

phpbb.add_ajax_callback = function(id, callback)
{
   if (typeof callback === 'function')
   {
      phpbb.ajax_callbacks[id] = callback;
   }
   return this;
}
It is from core.js, the original.

The function definition I suggested is this:

Code: Select all

phpbb.add_ajax_callback = function (id, callback) {
   if (typeof callback === 'function') {
      phpbb.ajax_callbacks[id] = callback;
   }
   return this;
}

edit: I've added a PR https://github.com/phpbb/phpbb3/pull/762/ if you all could comment there on the issues, it would be great.
There is a text here !

User avatar
callumacrae
Former Team Member
Posts: 1046
Joined: Tue Apr 27, 2010 9:37 am
Location: England
Contact:

Re: [RFC|Accepted] Coding Guideline Modifications

Post by callumacrae »

Hm, that function was fine when I wrote it xD

You can't the curly braces in one place without changing them everywhere.
Made by developers, for developers!
My blog

User avatar
naderman
Consultant
Posts: 1727
Joined: Sun Jan 11, 2004 2:11 am
Location: Berlin, Germany
Contact:

Re: [RFC|Accepted] Coding Guideline Modifications

Post by naderman »

Yes, this is a topic about coding guideline modifications. He is proposing to change the guidelines for Javascript code, and adapt all the code.

User avatar
callumacrae
Former Team Member
Posts: 1046
Joined: Tue Apr 27, 2010 9:37 am
Location: England
Contact:

Re: [RFC|Accepted] Coding Guideline Modifications

Post by callumacrae »

Oh. +1 to that :-D
Made by developers, for developers!
My blog

User avatar
naderman
Consultant
Posts: 1727
Joined: Sun Jan 11, 2004 2:11 am
Location: Berlin, Germany
Contact:

Re: [RFC|Accepted] Coding Guideline Modifications

Post by naderman »

I definitely prefer that style for javascript as well. So I would agree to changing coding guidelines to state that in Javascript opening braces go on the same line separated with a space.

User avatar
callumacrae
Former Team Member
Posts: 1046
Joined: Tue Apr 27, 2010 9:37 am
Location: England
Contact:

Re: [RFC|Accepted] Coding Guideline Modifications

Post by callumacrae »

Can we have camel-cap var and function names for JS, too? While PHP doesn't really have a standard, all the built in JS libraries use camel-caps, so it looks a bit weird to have anything else.
Made by developers, for developers!
My blog

User avatar
brunoais
Registered User
Posts: 964
Joined: Fri Dec 18, 2009 3:55 pm

Re: [RFC] Javascript Coding Style

Post by brunoais »

^
+1

User avatar
hanakin
Front-End Dev Team Lead
Front-End Dev Team Lead
Posts: 968
Joined: Sat Dec 25, 2010 9:02 pm
Contact:

Re: [RFC] Javascript Coding Style

Post by hanakin »

+1
Donations welcome via Paypal Image

Post Reply