
Constructores en Javascript considerados ligeramente confusos Traducido del Original en el blog code.h(oe)kje. Considerando la afirmación de Flanagan 2006, (página 111) que aparece en una pregunta de comp.lang.javascript el mes pasado: En javascript, cada objeto tiene una propiedad constructor que se refiere a la función constructor que inicializa el objeto. Suena bien: hace que los constructores parezcan estáticos como las clases en Java. Pero la vida no es tan simple: ¿Qué pasa? Objetos y métodos Los objetos en Javascript son simples bolsas de propiedades con nombre que pueden ser leidas y escritas. Las funciones en javascript son objetos de primera clase. Prototipos El prototipo (prototype) de un objeto es una propiedad interna a la que me referire como "[[Prototype]]" (como en Ecma-262). Los objetos javascript pueden delegar propiedades a su [[Prototype]] (y su [[Prototype]] puede hacer lo mismo; y así hasta Object Prototype). Búsqueda de propiedades ¿Qué está pasando? Esto es lo que las propiedades prototype y [[Prototype]] parecen. Notas al pie
Prototypal Inheritance Douglas Crockford www.crockford.com Five years ago I wrote Classical Inheritance in JavaScript (Chinese Italian Japanese). It showed that JavaScript is a class-free, prototypal language, and that it has sufficient expressive power to simulate a classical system. My programming style has evolved since then, as any good programmer's should. I have learned to fully embrace prototypalism, and have liberated myself from the confines of the classical model. My journey was circuitous because JavaScript itself is conflicted about its prototypal nature. new () produces a new object that inherits from .prototype This indirection was intended to make the language seem more familiar to classically trained programmers, but failed to do that, as we can see from the very low opinion Java programmers have of JavaScript. Fortunately, it is easy to create an operator that implements true prototypal inheritance. function object(o) { function F() {} F.prototype = o; return new F(); } if (typeof Object.create !
Using Prototype Property in JavaScript Exclusive offer: get 50% off this eBook here Object-Oriented JavaScript — Save 50% Create scalable, reusable high-quality JavaScript applications and libraries by Stoyan Stefanov | August 2008 | AJAX Web Development In this article by Stoyan Stefanov, you'll learn about the prototype property of the function objects. The following topics are discussed in this article: Every function has a prototype property and it contains an objectAdding properties to the prototype objectUsing the properties added to the prototypeThe difference between own properties and properties of the prototype__proto__, the secret link every object keeps to its prototypeMethods such as isPrototypeOf(), hasOwnProperty(), and propertyIsEnumerable() The functions in JavaScript are objects and they contain methods and properties. If you define a simple function foo() you can access its properties as you would do with any other object: >>>function foo(a, b){return a * b;}>>>foo.length >>>foo.constructor Function() "object" "foo"
An Introduction to YUI With jQuery dominating the JavaScript framework landscape, many newcomers aren't exposed to other JavaScript frameworks. The truth is that there are a plethora of excellent JavaScript frameworks available, like MooTools, Prototype, Ext JS, and...YUI! While not as well known as some of the other libraries, YUI provides a wealth of tools for the web developer. Today, we're going to take a quick tour of some of its features. What is YUI? YUI (short for Yahoo User Interface and pronounced Y-U-I) is an open source JavaScript and CSS library developed primarily by Yahoo.com. There are currently two supported versions of YUI. Why YUI? So you may be wondering, why should I even consider learning another JavaScript framework? Ok, now that you've heard a little about YUI, let's start looking at some code! Including the Library YUI allows for a lot of flexibility when it comes to loading the library; let's look at a couple ways you can do it. Method 1: YUI 3 Seed File Method 2: YUI 3 Configurator Events
Using Prototypes in Javascript | TimKadlec.com As mentioned in my previous post, I think using prototypes is powerful enough to deserve a more detailed explanation. To start off, let me say we are talking about the prototype method here, not the JavaScript library. Prototypes allow you to easily define methods to all instances of a particular object. function Pet(name, species){ this.name = name; this.species = species;}function view(){ return this.name + " is a " + this.species + "!" As you can see, by using simply using prototype when we attached the view method, we have ensured that all Pet objects have access to the view method. function Pet(name, species){ this.name = name; this.species = species;}function view(){ return this.name + " is a " + this.species + "!" We set up the Dog object, and have it call the Pet function using the call() method. Moving on, we then give Dog a custom method called bark that only Dog objects have access to. It is important to understand that prototype follows a chain.
Uniform - Sexy forms with jQuery Introduction to Object-Oriented JavaScript Object-oriented to the core, JavaScript features powerful, flexible OOP capabilities. This article starts with an introduction to object-oriented programming, then reviews the JavaScript object model, and finally demonstrates concepts of object-oriented programming in JavaScript. This article does not describe the newer syntax for object-oriented programming in ECMAScript 6. JavaScript review If you don't feel confident about JavaScript concepts such as variables, types, functions, and scope, you can read about those topics in A re-introduction to JavaScript. You can also consult the JavaScript Guide. Object-oriented programming Object-oriented programming (OOP) is a programming paradigm that uses abstraction to create models based on the real world. OOP envisions software as a collection of cooperating objects rather than a collection of functions or simply a list of commands (as is the traditional view). Terminology Namespace Class Defines the object's characteristics. Object Property Method
80 AJAX-Solutions For Professional Coding Advertisement Web-developers can create amazing web-applications with AJAX. Stikkit1, Netvibes2, GMail3 and dozens of further web-projects offer a new level of interactivity we’ve used to give up the idea of. Asynchronous JavaScript and XML isn’t a new programming language, as it is often mistakingly called. In this article we’d like to present a list of over 90 useful AJAX-based techniques you should always have ready to hand developing AJAX-based web-applications. You may also want to take a look at the article 60 More Ajax and Javascript Solutions For Professional Coding9. AJAX Auto Completer 1. 2. 3. 4. 5. AJAX Instant Edit 6. 7. 8. AJAX Menus, Tabs 9. 14 Tab-Based Interface Techniques18 10. 11. 12. 13. 14. 15. 16. 17. AJAX Date, Time, Calendars 18. 19. AJAX Interactive Elements 20. 21. 22. AJAX Developer’s Suite 23. 24. 25. 26. 27. 40+ Tooltips Scripts With AJAX, JavaScript & CSS | Smashing Magazine34 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. Enhanced AJAX Solutions 39. 40. 41. 42. 43.
Understanding JavaScript Prototypes. (en Español, русском, 中文) JavaScript’s prototype object generates confusion wherever it goes. Seasoned JavaScript professionals, even authors frequently exhibit a limited understanding of the concept. I believe a lot of the trouble stems from our earliest encounters with prototypes, which almost always relate to new, constructor and the very misleading prototype property attached to functions. In fact prototype is a remarkably simple concept. What is a prototype? A prototype is an object from which other objects inherit properties Can any object be a prototype? Yes. Which objects have prototypes? Every object has a prototype by default. OK back up, what is an object again? An object in JavaScript is any unordered collection of key-value pairs. You said every object has a prototype. Forget everything you learned about the prototype property – it’s probably the biggest source of confusion about prototypes. Ok fine, but false is a primitive, so why does false. Yes. OK. Example please? Like this:
Javascript/CSS Compression As some of you may know, I am currently working on a content management system. Although I am not able to share all of the code – it is proprietary after all – I already made one debugging tool public. This tool can be used to test some common techniques which decreases the bandwidth generated by feed consumers. Today I am going to make a second tool public – including source code. About six months ago I noticed the pages generated by the content management system were in itself very clean and small, but that these pages still took a long time to load for new visitors. The solution turned out the be simple, combine all the different files into a single large file and compress that file using gzip. Instead of going for the easy – but hard to maintain – solution I decided to automate the process and thanks to a small PHP script and some clever URL rewriting I now have an easy to maintain method to speed up the loading of pages that use many or large css and javascript files.
Private Members in JavaScript Douglas Crockford www.crockford.com JavaScript is the world's most misunderstood programming language. Some believe that it lacks the property of information hiding because objects cannot have private instance variables and methods. But this is a misunderstanding. Objects JavaScript is fundamentally about objects. If a value is a function, we can consider it a method. Objects can be produced by constructors, which are functions which initialize objects. Public The members of an object are all public members. In the constructor This technique is usually used to initialize public instance variables. function Container(param) { this.member = param; } So, if we construct a new object var myContainer = new Container('abc'); then myContainer.member contains 'abc'. In the prototype This technique is usually used to add public methods. Container.prototype.stamp = function (string) { return this.member + string; } So, we can invoke the method myContainer.stamp('def') which produces 'abcdef'. Private Closures