This document provides a summary of a talk on learning to love JavaScript. It discusses the speaker's background and experience, and outlines the talk in 5 parts:
1. Comfortable Confusion - Recalls the early days of JavaScript and how Java programmers initially dismissed it.
2. Collateral Damage - How JavaScript became associated with flashy websites and poor coding practices in the late 90s due to lack of interest from Java programmers.
3. Reconstruction - How the browser wars ended and JavaScript implementations improved in the 2000s, leading some to explore its potential again.
4. Revolution - How Google and toolkits/frameworks boosted JavaScript and Ajax in the mid-2000s, launching the current
Mon, August 22, 2:00pm – 2:30pm
Youtube: https://youtu.be/OlJZMHLTfuc
Description
Abstract: Spur is the new memory manager for the Cog virtual machine used by Pharo, Newspeak and Squeak. It features a two generation scavenger garbage collector with an adaptative tenuring policy, lazy become, (transparent) segmented memory, a new 64bit-compatible object-format, ephemerons, pinned objects, a class table, among others. If you're high-level application developer, or a programming amateur, but not a VM expert, but you're interested in understanding these concepts and what is their impact on your day to day development this talk is for you.
Bio: Guille Polito is research engineer at CNRS, France. Pharoer since 2010, he participates actively in the Pharo open source community since several years. He currently works on the modularization of Pharo where he does software archeology, refactoring, library rewriting and participates in the Virtual Machine development.
When you're writing a Ruby on Rails application, certain decisions seem appropriate and good at the beginning, but come back to bite you later on. In this talk, I list 20 different "traps," things that seem appealing, but which you should think twice before doing. The talk is based on my experience teaching Ruby and Rails classes to many people over the years, and was a presentation at the "Rails Israel 2012" conference held in Tel Aviv.
Mon, August 22, 2:00pm – 2:30pm
Youtube: https://youtu.be/OlJZMHLTfuc
Description
Abstract: Spur is the new memory manager for the Cog virtual machine used by Pharo, Newspeak and Squeak. It features a two generation scavenger garbage collector with an adaptative tenuring policy, lazy become, (transparent) segmented memory, a new 64bit-compatible object-format, ephemerons, pinned objects, a class table, among others. If you're high-level application developer, or a programming amateur, but not a VM expert, but you're interested in understanding these concepts and what is their impact on your day to day development this talk is for you.
Bio: Guille Polito is research engineer at CNRS, France. Pharoer since 2010, he participates actively in the Pharo open source community since several years. He currently works on the modularization of Pharo where he does software archeology, refactoring, library rewriting and participates in the Virtual Machine development.
When you're writing a Ruby on Rails application, certain decisions seem appropriate and good at the beginning, but come back to bite you later on. In this talk, I list 20 different "traps," things that seem appealing, but which you should think twice before doing. The talk is based on my experience teaching Ruby and Rails classes to many people over the years, and was a presentation at the "Rails Israel 2012" conference held in Tel Aviv.
JavaScript nicht nur für Programmierer: Einblicke in die weltweit am meisten ...Peter Hecker
Die meisten Programmierer haben von JavaScript schon mal gehört, meistens aber nichts Gutes. Dies basiert typischerweise auf Selbsterfahrung oder Hörensagen. Ist JavaScript überhaupt eine Programmiersprache? Können bzw. sollten richtige Programmierer damit arbeiten müssen? Gibt es Alternativen? In diesem Vortrag werden auf solche Frage Antworten gegeben. Lassen Sie sich, von der weltweit am meisten missverstandenen Programmiersprache überraschen: Ein Blick zurück - Wie alles begann, Der aktuelle Stand - JavaScript heute, Browser und JavaScript-Engines, JavaScript nicht nur im Browser: PhantomJS, Node.js, JavaScript-Bibliotheken, -Frameworks und -Tools, JavaScript-Alternativen: CoffeeScript, Dart, TypeScript, Ausblick und Fazit
Miller Columns (used in iPhone and Mac Finder) are an elegant way of displaying and navigating a tree. This talk describes a JavaScript implementation of Miller Columns, and why JavaScript needs modules and a standard library.
Presentation about a few situations at Apigee where we wanted/needed interoperability between Node.js and Java. One example is Hadoop-based MapReduce. During this presentation I discuss some use cases, some of the problems and then finish talking about technology that allows you to write MapReduce jobs using Node.js and run them natively on Hadoop as if written in Java.
As a guest speaker in NCU, I gave a talk about some best practices of JavaScript programming to college students. It covers basic JavaScript elements and some common pitfalls while dealing with asynchronous programming.
JavaScript nicht nur für Programmierer: Einblicke in die weltweit am meisten ...Peter Hecker
Die meisten Programmierer haben von JavaScript schon mal gehört, meistens aber nichts Gutes. Dies basiert typischerweise auf Selbsterfahrung oder Hörensagen. Ist JavaScript überhaupt eine Programmiersprache? Können bzw. sollten richtige Programmierer damit arbeiten müssen? Gibt es Alternativen? In diesem Vortrag werden auf solche Frage Antworten gegeben. Lassen Sie sich, von der weltweit am meisten missverstandenen Programmiersprache überraschen: Ein Blick zurück - Wie alles begann, Der aktuelle Stand - JavaScript heute, Browser und JavaScript-Engines, JavaScript nicht nur im Browser: PhantomJS, Node.js, JavaScript-Bibliotheken, -Frameworks und -Tools, JavaScript-Alternativen: CoffeeScript, Dart, TypeScript, Ausblick und Fazit
Miller Columns (used in iPhone and Mac Finder) are an elegant way of displaying and navigating a tree. This talk describes a JavaScript implementation of Miller Columns, and why JavaScript needs modules and a standard library.
Presentation about a few situations at Apigee where we wanted/needed interoperability between Node.js and Java. One example is Hadoop-based MapReduce. During this presentation I discuss some use cases, some of the problems and then finish talking about technology that allows you to write MapReduce jobs using Node.js and run them natively on Hadoop as if written in Java.
As a guest speaker in NCU, I gave a talk about some best practices of JavaScript programming to college students. It covers basic JavaScript elements and some common pitfalls while dealing with asynchronous programming.
In this core java training session, you will learn Elements of Java programming. Topics covered in this session are:
• Quick review of some important concepts from last class
• History of Java
• JDK and JRE
• Byte Code and JVM (Java Virtual Machine)
• Platform Independence
• Principles of Object Oriented Programming
• Writing your first Java Application
• Elements of Java programming language
• Built in Data Types
• Conditional Statements
• Loops
For more information about this course visit on this link: https://www.mindsmapped.com/courses/software-development/learn-java-fundamentals-hands-on-training-on-core-java-concepts/
In this session you will learn:
1. Principles of Object-Oriented Programming
2. Writing your first Java Application
3. Elements of Java programming language
4. Built in Data Types
5. Conditional Statements
6. Loops
LabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docxDIPESH30
Labs/Lab8.html
Lab 8: I'm Thinking of a Number
Before you begin this lab please review Javascript from the lecture notes.
This lab is meant to help you learn the rudiments of the Javascript programming language and understand something of how web pages use Javascript, well enough that you can write a basic Javascript program that implements a simple game. You will also begin to develop some appreciation of why programming is not entirely trivial. It really does require orderly thinking and meticulous attention to detail.
Please read these instructions before beginning the lab.
Please follow the instructions about program format, variable names, etc.
Please use the template in Part 3.
Please pay attention to syntax and grammar and language constructs.
You will have a better chance of success if you follow the highlighted hints. Things will work better if you do, and you may even find that programming is kind of fun, especially when your program works.
You can do this lab anywhere. Remember to post questions in the forum where you can get help from each other.Part 1: IntroductionPart 2: The Javascript LanguagePart 3: Writing your own Javascript ProgramPart 4: Finishing up
Part 1: Introduction - PREAMBLE 1
Programming languages provide a way to express computer algorithms in a form that is convenient for humans yet easily translated into a computer's machine language: programming languages are the way that we tell computers how to perform a task.
In the lecture notes, we have studied the very low-level instructions that the computer itself understands (for example, the Toy), and talked about a variety of programming languages, much easier for people to use, that are translated into machine instructions by programs like compilers and assemblers. There are many such languages, each with its own good and bad points, and often with noisy adherents and detractors.
Javascript, the topic of this lab and the next, is one of the most widely encountered languages, largely because it's available as part of every Web browser, and the majority of web pages include Javascript code. You too can write Javascript programs that will be run by whoever views your web page. We don't expect you to become a full-fledged Javascript programmer, but you will do enough in this lab and the next to get some understanding of what programs look like and what is involved in taking an algorithm and turning it into a program that implements the algorithm.
You'll also be able to better understand the Javascript pages that you encounter when you browse, and if you like, you'll be able to adapt and modify them for your own pages too.
There is an enormous amount of Javascript information on the Web, and thousands of books. You might start with this list of tutorials, or Google for "javascript tutorial".
Javascript has three major components:the Javascript language itselfbuilding blocks that you can use to create your programmethods that let your Javascript program inter ...
Similar to Glenn Vanderburg — Learning to love JavaScript (20)
Pushing the limits of ePRTC: 100ns holdover for 100 daysAdtran
At WSTS 2024, Alon Stern explored the topic of parametric holdover and explained how recent research findings can be implemented in real-world PNT networks to achieve 100 nanoseconds of accuracy for up to 100 days.
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
Climate Impact of Software Testing at Nordic Testing DaysKari Kakkonen
My slides at Nordic Testing Days 6.6.2024
Climate impact / sustainability of software testing discussed on the talk. ICT and testing must carry their part of global responsibility to help with the climat warming. We can minimize the carbon footprint but we can also have a carbon handprint, a positive impact on the climate. Quality characteristics can be added with sustainability, and then measured continuously. Test environments can be used less, and in smaller scale and on demand. Test techniques can be used in optimizing or minimizing number of tests. Test automation can be used to speed up testing.
PHP Frameworks: I want to break free (IPC Berlin 2024)Ralf Eggert
In this presentation, we examine the challenges and limitations of relying too heavily on PHP frameworks in web development. We discuss the history of PHP and its frameworks to understand how this dependence has evolved. The focus will be on providing concrete tips and strategies to reduce reliance on these frameworks, based on real-world examples and practical considerations. The goal is to equip developers with the skills and knowledge to create more flexible and future-proof web applications. We'll explore the importance of maintaining autonomy in a rapidly changing tech landscape and how to make informed decisions in PHP development.
This talk is aimed at encouraging a more independent approach to using PHP frameworks, moving towards a more flexible and future-proof approach to PHP development.
A tale of scale & speed: How the US Navy is enabling software delivery from l...sonjaschweigert1
Rapid and secure feature delivery is a goal across every application team and every branch of the DoD. The Navy’s DevSecOps platform, Party Barge, has achieved:
- Reduction in onboarding time from 5 weeks to 1 day
- Improved developer experience and productivity through actionable findings and reduction of false positives
- Maintenance of superior security standards and inherent policy enforcement with Authorization to Operate (ATO)
Development teams can ship efficiently and ensure applications are cyber ready for Navy Authorizing Officials (AOs). In this webinar, Sigma Defense and Anchore will give attendees a look behind the scenes and demo secure pipeline automation and security artifacts that speed up application ATO and time to production.
We will cover:
- How to remove silos in DevSecOps
- How to build efficient development pipeline roles and component templates
- How to deliver security artifacts that matter for ATO’s (SBOMs, vulnerability reports, and policy evidence)
- How to streamline operations with automated policy checks on container images
Essentials of Automations: The Art of Triggers and Actions in FMESafe Software
In this second installment of our Essentials of Automations webinar series, we’ll explore the landscape of triggers and actions, guiding you through the nuances of authoring and adapting workspaces for seamless automations. Gain an understanding of the full spectrum of triggers and actions available in FME, empowering you to enhance your workspaces for efficient automation.
We’ll kick things off by showcasing the most commonly used event-based triggers, introducing you to various automation workflows like manual triggers, schedules, directory watchers, and more. Plus, see how these elements play out in real scenarios.
Whether you’re tweaking your current setup or building from the ground up, this session will arm you with the tools and insights needed to transform your FME usage into a powerhouse of productivity. Join us to discover effective strategies that simplify complex processes, enhancing your productivity and transforming your data management practices with FME. Let’s turn complexity into clarity and make your workspaces work wonders!
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™UiPathCommunity
In questo evento online gratuito, organizzato dalla Community Italiana di UiPath, potrai esplorare le nuove funzionalità di Autopilot, il tool che integra l'Intelligenza Artificiale nei processi di sviluppo e utilizzo delle Automazioni.
📕 Vedremo insieme alcuni esempi dell'utilizzo di Autopilot in diversi tool della Suite UiPath:
Autopilot per Studio Web
Autopilot per Studio
Autopilot per Apps
Clipboard AI
GenAI applicata alla Document Understanding
👨🏫👨💻 Speakers:
Stefano Negro, UiPath MVPx3, RPA Tech Lead @ BSP Consultant
Flavio Martinelli, UiPath MVP 2023, Technical Account Manager @UiPath
Andrei Tasca, RPA Solutions Team Lead @NTT Data
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...SOFTTECHHUB
The choice of an operating system plays a pivotal role in shaping our computing experience. For decades, Microsoft's Windows has dominated the market, offering a familiar and widely adopted platform for personal and professional use. However, as technological advancements continue to push the boundaries of innovation, alternative operating systems have emerged, challenging the status quo and offering users a fresh perspective on computing.
One such alternative that has garnered significant attention and acclaim is Nitrux Linux 3.5.0, a sleek, powerful, and user-friendly Linux distribution that promises to redefine the way we interact with our devices. With its focus on performance, security, and customization, Nitrux Linux presents a compelling case for those seeking to break free from the constraints of proprietary software and embrace the freedom and flexibility of open-source computing.
Removing Uninteresting Bytes in Software FuzzingAftab Hussain
Imagine a world where software fuzzing, the process of mutating bytes in test seeds to uncover hidden and erroneous program behaviors, becomes faster and more effective. A lot depends on the initial seeds, which can significantly dictate the trajectory of a fuzzing campaign, particularly in terms of how long it takes to uncover interesting behaviour in your code. We introduce DIAR, a technique designed to speedup fuzzing campaigns by pinpointing and eliminating those uninteresting bytes in the seeds. Picture this: instead of wasting valuable resources on meaningless mutations in large, bloated seeds, DIAR removes the unnecessary bytes, streamlining the entire process.
In this work, we equipped AFL, a popular fuzzer, with DIAR and examined two critical Linux libraries -- Libxml's xmllint, a tool for parsing xml documents, and Binutil's readelf, an essential debugging and security analysis command-line tool used to display detailed information about ELF (Executable and Linkable Format). Our preliminary results show that AFL+DIAR does not only discover new paths more quickly but also achieves higher coverage overall. This work thus showcases how starting with lean and optimized seeds can lead to faster, more comprehensive fuzzing campaigns -- and DIAR helps you find such seeds.
- These are slides of the talk given at IEEE International Conference on Software Testing Verification and Validation Workshop, ICSTW 2022.
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
UiPath Test Automation using UiPath Test Suite series, part 4DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 4. In this session, we will cover Test Manager overview along with SAP heatmap.
The UiPath Test Manager overview with SAP heatmap webinar offers a concise yet comprehensive exploration of the role of a Test Manager within SAP environments, coupled with the utilization of heatmaps for effective testing strategies.
Participants will gain insights into the responsibilities, challenges, and best practices associated with test management in SAP projects. Additionally, the webinar delves into the significance of heatmaps as a visual aid for identifying testing priorities, areas of risk, and resource allocation within SAP landscapes. Through this session, attendees can expect to enhance their understanding of test management principles while learning practical approaches to optimize testing processes in SAP environments using heatmap visualization techniques
What will you get from this session?
1. Insights into SAP testing best practices
2. Heatmap utilization for testing
3. Optimization of testing processes
4. Demo
Topics covered:
Execution from the test manager
Orchestrator execution result
Defect reporting
SAP heatmap example with demo
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Albert Hoitingh
In this session I delve into the encryption technology used in Microsoft 365 and Microsoft Purview. Including the concepts of Customer Key and Double Key Encryption.
DevOps and Testing slides at DASA ConnectKari Kakkonen
My and Rik Marselis slides at 30.5.2024 DASA Connect conference. We discuss about what is testing, then what is agile testing and finally what is Testing in DevOps. Finally we had lovely workshop with the participants trying to find out different ways to think about quality and testing in different parts of the DevOps infinity loop.
2. About Me
Programmer since (gulp) 1979
Paid programmer since 1985
Java programmer since January 1995
Co-founder of JavaMUG
Author of first advanced Java book
Speaker at No Fluff, Just Stuff since 2003
Independent consultant, trainer, and speaker
Ruby, Agile, TDD, JavaScript, Ajax
3. About This Talk
My full introduction to JavaScript is 3 hours
… and it could easily be much longer.
This talk does get technical …
But first, it’s worth recalling how we got here.
5. Cast Your Mind Back …
January 1995: first public demonstration of Java
May 1995: Netscape licenses Java
October 1995: Navigator 2.0B1 supports Java
… and we hear the first mention of a web-page-based scripting
language called LiveScript.
The web is all abuzz about the coolness and potential of applets.
December 1995: Netscape renames LiveScript to
JavaScript and unveils it in Navigator 2.0B3
March 1996: First JavaScript talk at JavaMUG (by Greg
Graham)
6. A Bad Beginning
The decision to link JavaScript with Java—in
name and in syntax—proved to be a terrible one.
Clearly, Java programmers were in the best
position to understand and begin teaching it,
right?
7. “It’s a Toy!”
We early Java programmers took one look at
JavaScript and were revolted.
“Everything’s public!”
“No subclassing!”
“You can add and remove methods on existing objects!”
“You can change a property to a method!”
“I don’t know how to understand this language!!!”
JavaScript was a 10-day hack that got shipped.
We could tell.
8. The Result
Java programmers say “Avoid JavaScript.”
Keep all your logic on the server.
That’s where it belongs.
Use a real programming language.
Second JavaScript talk at JavaMUG?
George Lawniczak, “Ajax 101”, March 2006
A 10-year gap
10. Then, Things Got Ugly
Applets failed.
With nothing else useful to do, JavaScript became a
tool for flash and dazzle.
Widespread abuse.
Annoying layers that obscured the useful part of the
page.
Poorly tested JavaScript. Runtime bugs.
Security issues that prompted people to turn
JavaScript off.
Flashing images, scrolling status bars. Blechh.
11. Nature Abhors
a Vacuum
Java people showed no interest in learning to use
JavaScript well.
So the page designers filled the gap.
Widespread examples of poor JavaScript style.
Some in pages, some in books.
Nearly everyone learned JavaScript from those examples.
They failed to see the potential, except for visual effects.
Learning a language by example works well …
if the language is similar to what you already know.
12. You Ain’t Seen Ugly
Yet
Then: The Browser Wars
JavaScript was a primary weapon.
Along with the DOM
Rapid change, competing standards
Willful incompatibility
Infuriating bugs
13. … and Yet …
All along, I kept hearing people pay grudging
respect to JavaScript.
“It’s similar to NewtonScript.”
I knew enough about NewtonScript and its ancestor,
Self, to know that was a compliment.
“It would be great except for the browser.”
15. End of Browser Wars
Netscape gives up.
Mozilla and Firefox call a truce.
Microsoft shifts bug ray to CSS.
JavaScript implementations are actually pretty
good.
IE includes XMLHttpRequest, and Mozilla
follows suit.
How long before Java programmers wake up and
notice the changed situation?
16. Signs of Life
2000: Brent Ashley
Remote Scripting Resources site: www.ashleyit.com/rs/
JSRS (JavaScript Remote Scripting) and RSLite
2000: Alex Russell
netWindows (which became nWidgets, which gave rise
to Dojo)
Brent and Alex (and a few others) began exploring
the power of JavaScript and Ajax, long before that
term was invented.
17. Growth Outside
the Browser
Also during this period, JavaScript became the
default choice for an embedded scripting and
extension language.
Flash (ActionScript is a dialect of JavaScript)
Adobe applications: Photoshop, Illustrator, Acrobat,
etc.
Cocoon
Mac OS X apps: Sherlock, Konfabulator, Dashboard
Mozilla platform
MKS SourceIntegrity
18. It’s Always Darkest
Before Dawn
I don’t know the whole story of this period.
I was asleep in Java land.
June 2003: David Raphael showed me
netWindows, and I woke up.
25. My First Fluent
JavaScript
Budgeting/forecasting/three-year-planning app
Restaurants
Groceries
Meals
Car
Plane
Taxis
Transportation
Grand Total
2007
500
300
800
400
2,400
200
3,000
3,800
2008
450
300
750
500
2,200
250
2,950
3,700
2009
Total
425
1,375
275
875
700
2,250
550
1,450
2,100
6,700
300
750
2,950
8,900
3,650 11,150
26. Solution:
The Totalizator
to•tal•i•za•tor ¦ tōtl-i zātər¦
noun
A machine for computing and showing totals,
especially a pari-mutuel machine showing the
total number and amounts of bets at a
racetrack.
(The American Heritage Dictionary of the English Language,
Fourth Edition)
27. Solution:
The Totalizator
Table marked with an id attribute
Total column marked with total-column class
Subtotal rows marked with subtotal-row class
Grand total row marked with grand-total class
new Totalizator(‘forecast_table’);
28. How the Totalizator
Worked
Find the table using
document.getElementByID(table_id).
Traverse it looking for cells of various types,
building quick-reference lists.
Total everything up and set content in all total
cells.
Set observers on text fields to prompt
recalculation when cells are updated.
30. So Far, So Good
But it was a CRUD app.
My first version of Totalizator was great for
Create and Update.
Not necessary for Delete
What about Read?
Looking for text fields to observe ... we just don’t find
any.
Only other problem is reading a number from a cell.
32. What To Do?
Add an if statement to getNumberFromCell.
Nope. Too clumsy and specialized.
Remember: the only numbers are 0, 1, and many.
Write a subclass! ReadOnlyTotalizator!
Seems wrong somehow.
Plus, JavaScript doesn’t directly support subclasses.
I know! Use the Strategy pattern!
Killing flies with a bazooka …
33. Stop Thinking Java!
Functions are first-class objects in JavaScript.
Methods are just functions attached to objects.
You can add methods to classes at any time.
(Even after instances have been created.)
Individual objects can have their own methods!
34. An Easy Solution
function Totalizator(table_id, gnfc_function) {
this.table_id = table_id;
this.getNumberFromCell = gnfc_function;
// process table and find cells
}
new Totalizator(‘forecast_table’, function(cell) {
// logic to get number out of cell
});
35. That’s Easy?
Easy for Glenn to implement, maybe.
Not so easy for someone to use.
You have to supply a missing method every time
you create an instance!!!
36. Yeah, It’s Easy
Nobody said I couldn’t supply some useful
implementations …
Totalizator.getNumberFromSimpleCell = function(cell) {
return Number(cell.innerHTML);
}
Totalizator.getNumberFromTextInputCell = function(cell) {
return Number(cell.children[0].value);
}
Totalizator.prototype.getNumberFromCell =
Totalizator.getNumberFromSimpleCell;
37. One Final Update
Quickly revisit the constructor:
function Totalizator(table_id, gnfc_function) {
this.table_id = table_id;
if (arguments.length > 1)
this.getNumberFromCell = gnfc_function;
// process table and find cells
}
Now there’s some flexibility when creating:
new Totalizator(‘forecast_table’);
new Totalizator(‘forecast_table’,
Totalizator.getNumberFromTextInputCell);
38. How Does That Feel?
Sloppy? Maybe, if you’re still thinking in Java.
JavaScript is dynamic for good reasons.
Overengineered? I don’t think so.
Took a tiny bit of effort.
Easy to document.
Nice and DRY.
But you have to know the language!
39. What We Had to Know
Functions are first-class objects in JavaScript.
Methods are just functions attached to objects.
You can add methods to classes at any time.
(Even after instances have been created.)
Individual objects can have their own methods.
“Class” “constructors” are just functions.
Functions can have their own properties.
The arguments array lets you reflect on the argument list.
You can call functions or methods with too few (or too many)
arguments.
40. When we use a language,
we should commit ourselves to
knowing it, being able to read it,
and writing it idiomatically.
—Ron Jeffries
41. “The august Waldemar Horwat—who
was at one time the lead JavaScript
developer at Netscape—once told me that
he considered JavaScript to be just
another syntax for Common Lisp. I’m
pretty sure he was being serious.”
—Eric Lippert
42. JavaScript Is Weird
… unless you know NewtonScript or Self
(or, to a lesser degree, Smalltalk or CLOS)
Let’s look at a couple of the more interesting
aspects.
44. Functions Are Objects
The following two statements are equivalent:
function square(num) { return num*num; }
var square = function(num) { return num*num; };
You can use functions without names
Functions can (and do) have their own properties.
46. Variable Scope
In global scope, variables are resolved through
the global object.
add(accum, incr)
global
accum: 1
incr: 2
add: <function>
47. Variable Scope
Let’s see what happens in the body of that
function.
function add(a, b) {
return a + b;
}
<call>
__parent__:
a: 1
b: 2
arguments: [1, 2]
global
accum: 1
incr: 2
add: <function>
48. Lexical Scope
function f(x, y) {
g(x);
}
function g(z) {
alert(z);
}
f(3, 4);
What does the scope
chain look like when
alert is called?
global
f: <function>
g: <function>
alert: <function>
<call>
__parent__:
z: 3
arguments: [3]
49. Lexical Scope
function f(x, y) {
function g(z) {
alert(y);
alert(z);
}
g(x);
}
f(3, 4);
Does this change the
scope chain?
global
f: <function>
alert: <function>
<f’s call>
__parent__:
g: <function>
x: 3
y: 4
arguments: [3, 4]
<g’s call>
__parent__:
z: 3
arguments: [3]
50. Variable Scope:
Closures
That works even for
anonymous functions:
function f(x, y) {
return function (z) {
alert(y);
alert(z);
}
}
global
f: <function>
g: <function>
alert: <function>
<f’s call>
__parent__:
x: 3
y: 4
arguments: [3, 4]
<g’s call>
g = f(3, 4);
g(5)
__parent__:
z: 5
arguments: [5]
51. Variable Scope:
Closures
As part of XMLHttpRequest’s API, you must
supply callback functions.
XHR won’t pass them any parameters.
What if, in response to one of the XHR events,
you want to do some fairly complicated
processing with an element?
52. Variable Scope:
Closures
function ajaxDazzle() {
if (xhr.readyState != 4) return;
elem = document.getElementByID(‘item_list’);
// do complicated stuff
}
// …
xhr.onreadystatechange = ajaxDazzle;
OK, but what if ‘item_list’ isn’t the only element
you need this for?
53. Variable Scope:
Closures
function ajaxDazzler(elem_id) {
return function() {
if (xhr.readyState != 4) return;
elem = document.getElementByID(elem_id);
// do complicated stuff
};
}
// …
xhr.onreadystatechange = ajaxDazzler(‘item_list’);
55. Instance Variables
in Java
object.prop;
What happens?
Java finds the value of prop directly in the object.
But where does it come from?
At creation, all instance variables are created based on
declarations in the class and all superclasses.
56. Instance Variables
in JavaScript
object.prop;
What happens?
JavaScript looks for the value of prop directly in the
object.
If not found there, it looks in the object referenced by
the __proto__ property (usually the constructor’s
prototype).
The search continues until prop is found or __proto__ is
null.
57. Instance Variables
in JavaScript
But where does it come from?
Properties are usually created by the constructor.
Sometimes they already exist on the prototype when
the instance is created.
Often they’re added (in either place) after creation,
whether by a method or from the outside.
Point
point1
__proto__:
x: 1
y: 2
<prototype>
__proto__: <other prototype>
constructor: <function Foo>
name: “unnamed”
prototype:
58. Methods in Java
object.method();
What happens?
Java looks for prop in the object’s class.
If it’s not there, look in superclass.
Continue until found or superclass is null.
But where does it come from?
All methods are declared within classes when the
classes are declared.
59. Methods in JavaScript
object.method();
What happens?
JavaScript looks for the value of method directly in the
object.
If not found there, it looks in the object referenced by
the __proto__ property (usually the constructor’s
prototype).
The search continues until method is found or
__proto__ is null.
60. Instance Variables
in JavaScript
But where does it come from?
Methods are usually set on the prototype before the
instance is created.
Sometimes they’re created by the constructor.
Often they’re added (in either place) after creation,
whether by a method or from the outside.
Point
point1
__proto__:
x: 1
y: 2
to_polar: <function>
<prototype>
__proto__: <other prototype>
constructor: <function Foo>
name: “unnamed”
distance: <function>
prototype:
61. Properties
and Methods
In Java, instance variables and methods are very
different.
In JavaScript, they’re the same.
They’re usually created in different ways, but that’s just
the way people do it.
Neither works exactly the way they do in Java.
This can come in handy!
Add methods to individual objects.
Add an instance variable to all existing instances.
62. There’s More …
It’s all incredibly handy, once you embrace the
JavaScript philosophy.
Would I build an application server with it?
Probably not.
I wouldn’t port Swing to it, either.
But it’s remarkably well suited for the
environment inside a web page.
63. The really important thing
about Ajax is that it’s tricked us
into adopting a really powerful
language when we wouldn’t have
chosen to do so on our own.
—Stuart Halloway
64. Ajax is a gateway drug
for JavaScript.
—Stuart Halloway