Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Need explanation
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
  4 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
 
jakir  
View profile  
 More options Jul 7, 6:26 am
From: jakir <jakkir.sha...@gmail.com>
Date: Tue, 7 Jul 2009 03:26:51 -0700 (PDT)
Local: Tues, Jul 7 2009 6:26 am
Subject: Need explanation
 /* Based on Alex Arnell's inheritance implementation. */
var Class = {
  create: function() {
    var parent = null, properties = $A(arguments);
    if (Object.isFunction(properties[0]))
      parent = properties.shift();

    function klass() {
      this.initialize.apply(this, arguments);
    }

    Object.extend(klass, Class.Methods);
    klass.superclass = parent;
    klass.subclasses = [];

    if (parent) {
      var subclass = function() { };
      subclass.prototype = parent.prototype;
      klass.prototype = new subclass;
      parent.subclasses.push(klass);
    }

    for (var i = 0; i < properties.length; i++)
      klass.addMethods(properties[i]);

    if (!klass.prototype.initialize)
      klass.prototype.initialize = Prototype.emptyFunction;

    klass.prototype.constructor = klass;

    return klass;
  }

};

Class.Methods = {
  addMethods: function(source) {
    var ancestor   = this.superclass && this.superclass.prototype;
    var properties = Object.keys(source);

    if (!Object.keys({ toString: true }).length)
      properties.push("toString", "valueOf");

    for (var i = 0, length = properties.length; i < length; i++) {
      var property = properties[i], value = source[property];
      if (ancestor && Object.isFunction(value) &&
          value.argumentNames().first() == "$super") {
        var method = value;
        value = (function(m) {
          return function() { return ancestor[m].apply(this,
arguments) };
        })(property).wrap(method);

        value.valueOf = method.valueOf.bind(method);
        value.toString = method.toString.bind(method);
      }
      this.prototype[property] = value;
    }

    return this;
  }


    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.
david  
View profile  
 More options Jul 9, 8:05 am
From: david <david.brill...@gmail.com>
Date: Thu, 9 Jul 2009 05:05:26 -0700 (PDT)
Local: Thurs, Jul 9 2009 8:05 am
Subject: Re: Need explanation
Hi Jakir,

What is the question ?

--
david

On 7 juil, 12:26, jakir <jakkir.sha...@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.
jakkir hussain  
View profile  
 More options Jul 13, 3:47 am
From: jakkir hussain <jakkir.sha...@gmail.com>
Date: Mon, 13 Jul 2009 13:17:18 +0530
Local: Mon, Jul 13 2009 3:47 am
Subject: Re: [Proto-Scripty] Re: Need explanation

pls explain the above code ,what is does?


    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.
david  
View profile  
 More options Jul 14, 6:01 pm
From: david <david.brill...@gmail.com>
Date: Tue, 14 Jul 2009 15:01:16 -0700 (PDT)
Local: Tues, Jul 14 2009 6:01 pm
Subject: Re: Need explanation
Hi Jakkir,
the first part of the code introduce a new namespace called "Class"
with one method called "Create".
This portion when called with:
var myClass=Class.create({
  initialize:function(myVar){ ... },
  myMethod1:function(myVar1){ ... },
  myMethod2:function(myVar2){ ... },
  ...
});

var instance1=new myClass(myParameter);  //will create a new instance
of myClass class.
instance1.myMethod1(myParameter1);    //will launch the instance1
myMethod method
will create a new Class that will automatically launch the
myClass.initialize method: it's the constructor of the function.

But it also introduce inheritance, so you could create a new
"myNewClass" with the same method as "myClass". And you could also
overwrite "myClass" method in "myNewClass":
var myNewClass=Class.create(myClass,{
  initialize:function($super,myNewVar){
    ...
    //when need to call myClass constructor
    $super(myNewVar);
    ....
  },
  myNewMethod1:function($super,myNewVar1){ ... },
  MyNewLocalMethod:function(myLocalVar){ ... }

};

var newInstance1=new myNewClass(myNewParameter);
//this create a new instance of "myNewClass"
//internally, it will call the "myClass" constructor.
newInstance1.myNewMethod1(myParameter1);
//internally, it can call myMethod1 of "myClass".
newInstance1.MyNewLocalMethod(myLocalParameter1);
//method is only avalaible to the newInstance1 and not to instance1

The second part of the code is a extention that will added to you
instance so that you could extend properties of the instance created.

This a quite complicated portion of code wich need more than a thread
to be fully explained.
btw, I hope it demistify a little bit this code; if not, check:

for more information, first reed prototype API doc:
Class.create: http://prototypejs.org/api/class/create
addMethods: http://prototypejs.org/api/class/addMethods

you can also look at:
http://www.webreference.com/js/column79/index.html
http://ejohn.org/blog/simple-javascript-inheritance/#postcomment
--> also check comments for this post
http://www.sitepoint.com/blogs/2006/01/17/javascript-inheritance/

--
daivd

On 13 juil, 09:47, jakkir hussain <jakkir.sha...@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.
End of messages
« Back to Discussions « Newer topic     Older topic »

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