Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Class#create and throw new Error()
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Ilya Furman  
View profile  
 More options Nov 6 2009, 11:23 am
From: Ilya Furman <smashl...@gmail.com>
Date: Fri, 6 Nov 2009 08:23:05 -0800 (PST)
Local: Fri, Nov 6 2009 11:23 am
Subject: Class#create and throw new Error()
Hello!

I'm wondering, why class instance is being created while
initialization method throws an error?

var C = Class.create({
  initialization : function() {
    throw new Error('Hey, you can\'t have any instances of this
class!')
  },
  foo : 'foofoo' ,
  bar : function() {
    alert(this.foo)
  }

});

var c = new C();
c.bar();

Demo link http://jsbin.com/inoqi

Variable c should be 'undefined' I suppose, without any methods and
properties.
Seems like there is actually no way to stop instance from being
created.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
T.J. Crowder  
View profile  
 More options Nov 7 2009, 9:44 am
From: "T.J. Crowder" <t...@crowdersoftware.com>
Date: Sat, 7 Nov 2009 06:44:23 -0800 (PST)
Local: Sat, Nov 7 2009 9:44 am
Subject: Re: Class#create and throw new Error()
Hi,

The initializer is called "initialize", not "initialization" (see the
docs[1]).  Your code throwing the exception isn't being called, hence
the exception not being thrown.  If you use the correct name, the
exception is thrown and correctly propagates out to the code creating
the object.

[1] http://api.prototypejs.org/language/class.html

HTH,
--
T.J. Crowder
Independent Software Consultant
tj / crowder software / com
www.crowdersoftware.com

On Nov 6, 4:23 pm, Ilya Furman <smashl...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ilya Furman  
View profile  
 More options Nov 7 2009, 7:40 pm
From: Ilya Furman <smashl...@gmail.com>
Date: Sun, 8 Nov 2009 02:40:44 +0200
Local: Sat, Nov 7 2009 7:40 pm
Subject: Re: [Prototype-core] Re: Class#create and throw new Error()
Oops, my bad.

Ilya Furman


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google