This link has been bookmarked by 127 people . It was first bookmarked on 19 Sep 2006, by Stjepan.
-
05 Apr 12
-
24 Jan 12
-
15 Jul 11
borislv很完整的介紹Javascript Object。還有closure的應用也很清楚。但並非介紹繼承。
-
object literal
-
just a shortcut to creating objects
-
object literal
-
the same
-
object.property
-
object['property']
-
brackets to shorten
-
alternate
new Object() -
creating a function creates an object
-
function is an object
-
Function objects can be a little more useful
-
they can be used as a template for new objects
-
class
-
really only want one manager
-
don’t need to provide a mechanism for creating more
-
object literal is a fine choice
-
the
new -
function
-
new Animation(obj)
-
blank object
-
function
-
add properties
-
aren’t part of the template
-
these additional properties
-
new Animation
-
undefined
-
thousand copies of each method and property
-
objects
-
all reference the same methods and properties
-
template’s
prototype -
prototype
-
onStart
-
new Animation
-
onStart
-
any time
-
new Animation
-
prototype
-
onStart
-
onStart
-
return an object as a result of a constructor
-
object will get used as the new object instead of the blank object
-
not be available
-
new Animation
-
nutshell
-
private variables
-
construct
-
return new construct
-
new
constructobject -
loopCountandloopwill be the only ones we have access to -
control when animations start or stop
-
AnimationManager
-
methods
-
the
this -
properties
-
newon an anonymous function -
use a function to create objects
-
maintainable
-
Objects
-
great asset
-
-
27 Apr 11
-
18 Mar 11
Hyung-Joo LimDigital Web Magazine - Objectifying JavaScript - Muy interesante. Habla de las diferentes maneras de crear objetos. http://ow.ly/1bKtdx
-
11 Jul 10
-
The important idea here is simply that objects encapsulate related functionality.
-
objects allow us to handle variable scope in a contained way, and simply keeps our code cleaner
-
Property names get converted to strings, meaning that the string “25” and the integer 25 boil down to the same thing: Whichever gets declared last overwrites the other.
-
Accessing Object Properties
-
alert(AnimationManager.framesPerSecond); // object.property
alert(AnimationManager['framesPerSecond']); // object['property'] -
Using a Function
-
a function is an object; creating a function creates an object
-
they can be used as a template for new objects
-
For example, we created an
AnimationManagerin the previous section using an object literal. We really only want one manager, so we don’t need to provide a mechanism for creating more; the object literal is a fine choice for this object. Let’s extend the example a bit, and assume that theAnimationManagercontrols multipleAnimationobjects. If we defineAnimationusing an object literal, we’ll have to write the same code over and over again as we animate more elements in order to ensure that each new object has the proper methods and properties. Creating each animation object from a base template provides a solution for this problem. -
Using a Template
-
When
new Animation(obj)is executed, a blank object is created in the background, and theAnimationfunction is evaluated, referencing the new object as itsthiskeyword -
It’s important to note that we can add properties onto the
Animationfunction itself, just like the object literal:function Animation() { }
Animation.animationLength = 30;
Animation.element = element;The difference here is that these additional properties aren’t part of the template. If we executed
new Animation()from the code above, we’d get back a blank object, not an object with two properties. For example:var animateLogin = new Animation(loginform);
Animation.animationLength = 30;
alert(animateLogin.element); // the 'loginform' element
alert(animateLogin.animationLength); // undefined! -
Prototype
-
creating a thousand
Animationobjects would create a thousand copies of each method and property, taking up valuable memory -
there’s a way to create object templates that generate objects that all reference the same methods and properties: We attach properties to the template’s
prototype. -
In short, a call to a property of an object first checks the object itself for the property; if it doesn’t exist, it’ll check it’s template’s
prototype; we’ll only have one version of the property stored in memory, no matter how many objects we create. -
We can add to the template’s
prototypeat any time, and the new properties will automatically be available, even on object’s we’ve already created. -
function Animation(element){
this.animationLength = 30;
Animation.element = element;
}
var animateLogin = new Animation(loginform);
Animation.prototype.onStart = function() {
alert("The animation is beginning!");
};
Animation.prototype.onEnd = function() {
alert("The animation is ending!");
}; -
animateLogin.onStart(); -
Even though we create the new
Animationbefore we define theonStartandonEndmethods, we can still use them! This is a huge advantage of theprototype-based approach.
-
-
22 Apr 10
Marg Wilkinsongood tutorial on functions
javascript oop tutorials singelton pattern advanced functions
-
10 Mar 10
-
11 Dec 09
Michael FedderThe web professional's online magazine of choice.
Objectifying JavaScript -
12 Nov 09
-
29 Jun 09
-
25 Sep 08
-
09 Jul 08
-
07 Jul 08
-
31 May 08
-
14 Apr 08
-
12 Apr 08
-
28 Mar 08
-
23 Feb 08
-
16 Feb 08
-
07 Feb 08
-
15 Jan 08
Attila GyörffyAs scripts get larger, functions become more interrelated. Suddenly, you’ve got ten functions on a page, six of them calling each other to accomplish one task, and another four working towards something else entirely.
-
31 Aug 07
-
07 Aug 07
-
24 Jun 07
-
18 Jun 07
-
17 Jun 07
-
mariusz wWhen I first began programming with JavaScript, I created my variables and then encapsulated any functionality I needed to reuse into a function. As my tasks got more complicated and as I started learning object-oriented programming in other languages...
-
16 Jun 07
-
14 May 07
-
25 Mar 07
-
24 Mar 07
-
22 Feb 07
-
16 Feb 07
-
06 Feb 07
-
29 Jan 07
-
26 Jan 07
-
12 Jan 07
-
22 Dec 06
-
13 Dec 06
-
07 Dec 06
-
13 Nov 06
-
25 Oct 06
-
21 Oct 06
-
17 Oct 06
-
12 Oct 06
-
07 Oct 06
-
01 Oct 06
-
30 Sep 06
Javier PimientaWhen I first began programming with JavaScript, I created my variables and then encapsulated any functionality I needed to reuse into a function. As my tasks got more complicated and as I started learning object-oriented programming in other languages, I
-
22 Sep 06
-
21 Sep 06
-
20 Sep 06
-
19 Sep 06
Gary BurgeWhen I first began programming with JavaScript, I created my variables and then encapsulated any functionality I needed to reuse into a function. As my tasks got more complicated and as I started learning object-oriented programming in other languages, I
-
09 Dec 05
Page Comments
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.