background preloader

Prog

Facebook Twitter

Five ways to create objects… 1. Simple Object Literal myApp.notepad = {}; myApp.notepad.writeable = true; myApp.notepad.font = 'helvetica'; myApp.notepad.setFont = function(theFont) { myApp.notepad.font = theFont; } 2. Nested Object Literal 3. Constructor using Object Literal myApp.Notepad = function(defaultFont) { var that = {}; that.writeable = true; that.font = defaultFont; that.setFont = function(theFont) { that.font = theFont; } return that; } myApp.notepad1 = myApp.Notepad('helvetica'); 4. MyApp.Notepad = function(defaultFont) { this.writeable = true; this.font = defaultFont; this.setFont = function(theFont) { this.font = theFont; } } myApp.notepad1 = new myApp.Notepad('helvetica'); 5.

MyApp.Notepad = function(defaultFont) { this.font = defaultFont; } myApp.Notepad.prototype.writeable = true; myApp.Notepad.prototype.setFont = function(theFont) { this.font = theFont; } myApp.notepad1 = new myApp.Notepad('helvetica'); The first two examples are best suited for creation of one-time objects. All are useful. Like this: AppcodingEasy.com. Javascript Orienté Objet : syntaxe de base des classes JS à l’intention des développeurs PHP. Ce tuto a pour cible les développeurs qui ont une expérience du PHP (5) et qui veulent se lancer dans un projet Javascript qui dépasse le simple scripting. Cela va donc commencer par savoir écrire des classes en JS. Pour avoir galéré en tant que développeur puis en tant que lead technique avoir formé de bons développeurs PHP à faire des applications Web où le JS représente plus d’un tiers du code et la moitié du temps de dev, j’ai pu constater les énervements classiques lorsqu’on commence à vouloir faire des choses sérieuses en JS.

Le but ici n’est pas de rentrer dans la théorie du langage JS ou même d’être exhaustif (voir à la fin de cet article des ressources qui le font très bien) mais de vous fournir un template pour commencer à écrire vos classes. Quand on arrive du PHP, du C ou même de Java, JavaScript peut être franchement surprenant. Concrètement il y a 2 choses à comprendre pour éviter les erreurs classiques et partir sur une bonne base de code pour programmer avec des objets : Les objets en Javascript. HTML5 Presentation. In March 1936, an unusual confluence of forces occurred in Santa Clara County. A long cold winter delayed the blossoming of the millions of cherry, apricot, peach, and prune plum trees covering hundreds of square miles of the Valley floor. Then, unlike many years, the rains that followed were light and too early to knock the blossoms from their branches. Instead, by the billions, they all burst open at once.

Seemingly overnight, the ocean of green that was the Valley turned into a low, soft, dizzyingly perfumed cloud of pink and white. Uncounted bees and yellow jackets, newly born, raced out of their hives and holes, overwhelmed by this impossible banquet. Then came the wind. It roared off the Pacific Ocean, through the nearly uninhabited passes of the Santa Cruz Mountains and then, flattening out, poured down into the great alluvial plains of the Valley.