webOS Nation Forums >  webOS apps and software >  webOS development > Style Question Re: JavaScript in WebOS App
Style Question Re: JavaScript in WebOS App

  Reply
 
LinkBack Thread Tools Display Modes
Old 07/10/2009, 08:10 AM   #1 (permalink)
Member
 
sacherjj's Avatar
 
Join Date: Jun 2009
Location: Indianapolis, IN
Posts: 1,686
Likes Received: 0
Thanks: 41
Thanked 365 Times in 215 Posts
Default Style Question Re: JavaScript in WebOS App

These seem to be two different styles of JavaScript for WebOS development

Code:
function AppAssistant() {
  });

}

AppAssistant.prototype.initialize = function() {
};

AppAssistant.prototype.setup = function() {
};
Code:
AppAssistant = Class.create({
	initialize: function(controller){
	},
	
	setup: function(){

	}	
});
The first seems to be used more, but the second is more space efficient. Which do you prefer and why?
sacherjj is offline   Reply With Quote
Old 07/10/2009, 09:18 AM   #2 (permalink)
Member
 
Blubble's Avatar
 
Join Date: Jun 2009
Location: Silicon Valley, California
Posts: 1,025
Likes Received: 0
Thanks: 37
Thanked 444 Times in 161 Posts
Default

The first does seem to be used more for the Assistants. I am not sure if there are any specific benefits over the class.create for the assistants.

Strangely, the Palm devs used the class.create more often for the stock apps, but the sample apps mostly used the AppAssistant.prototypes syntax.

However, for custom objects I always use the create.class method as it is definitely more flexible for those purposes.
Blubble is offline   Reply With Quote
Old 07/10/2009, 10:08 AM   #3 (permalink)
Member
 
sacherjj's Avatar
 
Join Date: Jun 2009
Location: Indianapolis, IN
Posts: 1,686
Likes Received: 0
Thanks: 41
Thanked 365 Times in 215 Posts
Default

I was noticing the difference between what Palm did and what Palm said.

I have tried it both ways and don't see anything lacking with the later option. Just wondering if I missed something.
sacherjj is offline   Reply With Quote
Old 07/10/2009, 10:38 AM   #4 (permalink)
Member
 
TheMarco's Avatar
 
Join Date: Jun 2009
Location: Sunnyvale CA
Posts: 699
Likes Received: 6
Thanks: 19
Thanked 160 Times in 72 Posts
Default

It's just a different way of constructing objects. There's no real difference I think except for the second one being a bit more appealing to people with a JAVA background.
TheMarco is offline   Reply With Quote
Old 07/10/2009, 11:05 AM   #5 (permalink)
Member
 
Join Date: Jun 2009
Location: Germany
Posts: 122
Likes Received: 0
Thanks: 13
Thanked 395 Times in 32 Posts
Default

I'm using the second one because it just looks better.
__________________
My Apps - Donations :-)
roar is offline   Reply With Quote
Old 07/10/2009, 11:12 AM   #6 (permalink)
Legend
 
Jason Robitaille's Avatar
 
Join Date: May 2005
Location: Winnipeg, MB, Canada
Posts: 3,883
Likes Received: 496
Thanks: 801
Thanked 12,956 Times in 1,495 Posts
Default

Either works I believe. Palm seems to have Prototype built into the framework, so that might be connected. I could be wrong, but it seems just a matter of preference.

Last edited by Jason Robitaille; 07/10/2009 at 01:20 PM.
Jason Robitaille is offline   Reply With Quote
Old 07/10/2009, 11:15 AM   #7 (permalink)
Member
 
sacherjj's Avatar
 
Join Date: Jun 2009
Location: Indianapolis, IN
Posts: 1,686
Likes Received: 0
Thanks: 41
Thanked 365 Times in 215 Posts
Default

Quote:
Originally Posted by Jason Robitaille View Post
Either works I believe. Palm seems to have Prototype built into the framework and is a viable option. One just seems to be done with Prototype and the other seems without it. I could be wrong, but it seems just a matter of preference.

The prototype in this sense is nothing to do with the Prototype framework. It is a JavaScript property to add something to all instances of the object.

The first example is building an object and then adding on functionality down the file. The second is creating an object with all the functionality in one swipe.

I don't know if there is a performance advantage either way, other than reading and parsing the extra text for the first. There might be an advantage of not messing up the list in the second with a more formal "prototype" version.

Last edited by sacherjj; 07/10/2009 at 11:29 AM.
sacherjj is offline   Reply With Quote
Thanked By: Jason Robitaille
Old 07/10/2009, 12:22 PM   #8 (permalink)
Member
 
Blubble's Avatar
 
Join Date: Jun 2009
Location: Silicon Valley, California
Posts: 1,025
Likes Received: 0
Thanks: 37
Thanked 444 Times in 161 Posts
Default

The class.create syntax is part of the Prototype framework. The .prototype in the assistants is just plain old javascript.
Blubble is offline   Reply With Quote
Old 07/10/2009, 12:54 PM   #9 (permalink)
Member
 
sacherjj's Avatar
 
Join Date: Jun 2009
Location: Indianapolis, IN
Posts: 1,686
Likes Received: 0
Thanks: 41
Thanked 365 Times in 215 Posts
Default

Quote:
Originally Posted by Blubble View Post
The class.create syntax is part of the Prototype framework. The .prototype in the assistants is just plain old javascript.
Ahh. Gotcha. That explains why it was vaguely familiar to me. I messed with Prototype a while back, but not much since.

Last edited by sacherjj; 07/10/2009 at 05:50 PM.
sacherjj is offline   Reply With Quote
Old 07/10/2009, 05:26 PM   #10 (permalink)
Member
 
Join Date: Jun 2009
Posts: 204
Likes Received: 18
Thanks: 5
Thanked 18 Times in 14 Posts
Default

Dude, thank you for asking this question. I've been wondering the same thing. Although I was under the impression that they both used the prototype framework.

Coming from an ANSI C background (damn you OOP!) I can read the .prototype method a lot more clearly. It just seems to make more sense. For some reason, I feel like I should be reading the class.create method backwards. The use of colons reminds me too much of BASIC.
mattbrad2 is offline   Reply With Quote
Reply

 

Thread Tools
Display Modes



 


Content Relevant URLs by vBSEO 3.6.0