Finally we call our original method, it does its work (possibly making
use of _super as well) after which we restore _super to its original
state and return from the function.


I’ve been doing a lot of work, lately, with JavaScript inheritance –
namely for my ca88手机版会员登录 ,work-in-progress JavaScript
book – and in doing so
have examined a number of different JavaScript
classical-inheritance-simulating techniques. Out of all the ones that
I’ve looked at I think my favorites were the implementations employed
by base2 andPrototype.


if ( !initializing )
  this.init.apply(this, arguments);

  时 间:2018年3月23日(周五)9:00—11:00

Thus when it comes time to actually construct the function we make sure
that we’re not in an initialization mode and run the init method


What’s especially important about this is that the init method could be
running all sorts of costly startup code (connecting to a server,
creating DOM elements, who knows) so circumventing this ends up working
quite well.

  地 点:北京师范大学哲学学院 主楼A802

A couple things to note about this implementation:


I wanted to go about extracting the soul of these techniques into a
simple, re-usable, form that could be easily understood and didn’t have
any dependencies. Additionally I wanted the result to be simple and
highly usable. Here’s an example of what you can do with it:


Now there’s a number of ways in which a similar result, to the above,
could be achieved (I’ve seen implementations that have bound the super
method to the method itself, accessible from arguments.callee) but I
feel that this technique provides the best mix of usability and

  In ‘The Refutation of Idealism’ (1903) GE Moore famously argues that
a certain claim is both the basis for believing that ‘esse is percipi’
and self-contradictory. The claim in question is the identification of
the sensation of blueness with the object of the sensation, namely
blueness – or perhaps an instance of blueness – itself. Call this claim
‘Objectualism’ about the sensation. The connection between Objectualism
and the esse is percipi thesis was noted by Berkeley 200 years ealrier,
though he did not think Objectualism was self-contradictory. In this
paper I first defuse Moore’s charge of self-contradiction before
defending Objectualism on two grounds: first, that if we accept the
argument that naïve realism best explains the phenomenology of
perception, especially what is called transparency, then Objectualism
provides a better explanation than other relationist forms of naïve
realism; and secondly, Objectualism avoids the most problematic forms of
the hard problem of consciousness (something Berkeley also noted at the
start of the second of the Three Dialogues – see Stoneham 2013). Neither
Berkeley nor Moore suggest that Objectualism alone entails that esse is
percipi, but it does provide a fertile starting point for idealism.

In my opinion the two trickiest parts are the “initializing/don’t call
init” and “create _super method” portions. I want to cover those
briefly so that you will have a good understanding of what’s being
achieved in this method.

  主讲人:Prof. Tom Stoneham


  Tom Stoneham is professor at the department of philosophy, and Dean
of Graduate Research School, Vice Chancellor’s Office, University of
York. His research areas of specialization include: 17th/18th Century
British Philosophy, Philosophy of Mind: Self-Knowledge, Perception,
Consciousness, Dreaming, and Metaphysics of Modality and Time. His main
publications are:(1)Berkeley’s World: An Examination of the Three
Dialogues. 2002;(2)Causation and Modern Philosophy. (ed.)
2011;(3)Locke and Leibniz on Substance. (ed.) 2015.

For example, if you wanted to call a super-classes’ constructor you
could do that with this technique.


Super Method

  • Creating a constructor had to be simple (in this case simply
    providing an init method does the trick).
  • In order to create a new ‘class’ you must extend (sub-class) an
    existing class.
  • All of the ‘classes’ inherit from a single ancestor: Class.
    Therefore if you want to create a brand new class it must be a
    sub-class of Class.
  • And the most challenging one: Access to overridden methods had to be
    provided (with their context properly set). You can see this with
    the use of this._super(), above, calling the
    original init() and dance() methods of the Person super-class.

Note that we create an anonymous closure (which returns a function) that
will encapsulate the new super-enhanced method. To start we need to be a
good citizen and save a reference to the old this._super (disregarding
if it actually exists) and restore it after we’re done. This will help
for the case where a variable with the same name already exists (don’t
want to accidentally blow it away).

Implementing this functionality is a multi-step process. To start, note
the object literal that we’re using to extend an existing class (such as
the one being passed in toPerson.extend) needs to be merged on to the
base new Person instance (the construction of which was described
previously). During this merge we do a simple check: Is the property
that we’re attempting merge a function and is what we’re replacing also
a function? If that’s the case then we need to go about creating a way
for our super method to work.


电子邮件地址不会被公开。 必填项已用*标注