I have only clients no boses, who blame it on jQuery .... until they
are caught that is ;o)
I am catching them with jQ version I have "adorned" with this kind of
checks like the one we are discussing here.
You will be amazed (same as me) what are javascript/css/html newcomers
capable of doing.
One more check I am going to add is this one to stop them doing new $
() ...

Thanks

--DBJ

On May 15, 10:43 am, Andrea Giammarchi <[email protected]>
wrote:
> Tell your head of "whatever" that a title in a contract does not necessary
> mean extraordinary skills and if he would like to improve his JavaScript
> knowledge he is more than welcome in this ml ( probably more as reader ... )
> anyway ...
>
> function init(selector, context){
>     if(this instanceof jQuery)
>         throw new Error( jQuery.error_code,  "Can not new $()");
>     return new jQuery.fn.init(selector, context);
>
> };
>
> function jQuery(selector, context) {
>     return jQuery.fast ?
>         new jQuery.fn.init(selector, context) :
>         init.call(this, selector, context)
>     ;
>
> };
>
> Conditional is a bit faster than an if but still it is something that does
> not make sense because as I said the nature of the jQuery callback is dual (
> both function/constructor ... it does not matter which way you call it, the
> result will always be an instance of jQuery, if "you" like weist time
> writing an alread implicit "new" everywhere, it cannot be a jQuery issue, do
> you agree? )
>
> On Fri, May 15, 2009 at 10:20 AM, Daniel Friesen
> <[email protected]>wrote:
>
>
>
> > ;) I still see an if statement there, heh.
>
> > I prefer the conditional comments + build system approach.
>
> > ~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name]
>
> > DBJDBJ wrote:
> > > "... If a user uses new $ this user simply does not truly understand/
> > > know
> > > JavaScript but fortunately will not harm anybody..."
>
> > > No it wont, unless this user is a team leader and starts blaming
> > > jQuery on everything.
> > > And this happens much more than anyone here (it seems) realises.
> > > But. This is another subject.
>
> > > PS:
>
> > > jQuery.fast = false  ;
> > > jQuery.error_code = 0xABCD ;
>
> > >  function(selector, context) {
> > >      if ( ! jQuery.fast)
> > >                    if(this instanceof jQuery)
> > >                             throw new Error( jQuery.error_code,  "Can
> > > not new $()");
> > >      return new jQuery.fn.init(selector, context);
> > >   }
>
> > > On May 14, 2:59 pm, Andrea Giammarchi <[email protected]>
> > > wrote:
>
> > >> to do that you need to change the contructor:
>
> > >> function(selector, context) {
> > >>     if(this instanceof jQuery)
> > >>         throw new Error("Can not new $()");
> > >>     return new jQuery.fn.init(selector, context);
>
> > >> }
>
> > >> this means an extra if for each jQuery call, something not that welcome
> > for
> > >> performances reason. At the same time, jQuery itself relies in this
> > >> JavaScript peculiarity, so I would not create "conflicts" between jQuery
> > >> developers and users.
>
> > >> If a user uses new $ this user simply does not truly understand/know
> > >> JavaScript but fortunately will not harm anybody.
>
> > >> On Thu, May 14, 2009 at 10:23 AM, DBJDBJ <[email protected]> wrote:
>
> > >>> Ah, new $, is possible and therefore not barred ... Left in there as a
> > >>> sort of a land-mine for the newcomers ? Or as an esoteric test for GC
> > >>> developers ? Highly useless it seems to me.
>
> > >>> Back to reality and jQuery. $ is defined as:
>
> > >>> function(selector, context) {
> > >>>            // The jQuery object is actually just the init constructor
> > >>> 'enhanced'
> > >>>            return new jQuery.fn.init(selector, context);
> > >>>        }
>
> > >>> Maybe I am just searching for ECMA "harmony", but will $() definition
> > >>> that throws an exception if new-ed , be usefull  :
>
> > >>> try {
> > >>>        new $ ;
> > >>> } catch ( x )
> > >>> {
> > >>>    // x. message == "Can not new $()"
> > >>> }
>
> > >>> Au-contraire : will this hurt anyone ? Is exception throwing
> > >>> porgramming idiom damaging for jQuery?
>
> > >>> --DBJ
>
> > >>> PS: if Python was choosen as a Netscape scripting language,  World
> > >>> would be a better place ... If nothing else its name is less
> > >>> ridiculous ... ;o)
>
> > >>> On May 14, 9:04 am, Andrea Giammarchi <[email protected]>
> > >>> wrote:
>
> > >>>> it's called JavaScript :D
>
> > >>>> jokes a part, every function is a constructor as well so new function
> > is
> > >>>> always valid.
>
> > >>>> If the function returns an object, it does not matter which "new" is
>
> > >>> because
>
> > >>>> it will be an instance of returned object one.
>
> > >>>> if it is a primitive it will simply be lost:
>
> > >>>> var a = new function(){return 123;};
> > >>>> // a is an instance of anonymous function
>
> > >>>> this allows us to create Python like initializations:
>
> > >>>> function PythonLike(){
> > >>>>     return this instanceof arguments.callee ? this : new
>
> > >>> arguments.callee;
>
> > >>>> };
>
> > >>>> alert(PythonLike() instanceof PythonLike);
> > >>>> alert(new PythonLike() instanceof PythonLike);
>
> > >>>> true in both cases
>
> > >>>> jQuery returns a new jQuery.prototype.init where init method shares
> > the
>
> > >>> same
>
> > >>>> prototype ... better now? :-)
>
> > >>>> On Wed, May 13, 2009 at 11:57 PM, DBJDBJ <[email protected]> wrote:
>
> > >>>>> Why is this allowed :
>
> > >>>>> var jq = new $ ;
>
> > >>>>> Does it matter?
>
> > >>>>> -- DBJ
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to