This is the slide stack to the two JavaScript Operators YouTube videos at https://www.youtube.com/watch?v=4sF-9RqDxEA and https://www.youtube.com/watch?v=lRijlc3tsw0
Does what it says on the tin. An introduction to Modern Perl programming aimed at programmers who have little or no experience in Perl.
I gave this course at the London Perl Workshop in November 2013.
Called “downcase” on nil? Forgot to return the right object in one of your logic branches? Called “first” on a String instead of an Array and spent half an hour trying to figure out why a single character was getting passed around everywhere?
At Grailed, these situations were not uncommon. We are the largest marketplace for luxury men's fashion, with over 7 million users, and a growing Rails codebase that spans hundreds of thousands of lines. Before typing, changes to core interfaces often required creative grepping, modification of type checking unit tests, and updating brittle type documentation.
Ever since we started gradually typing our codebase with Sorbet, we’ve been able to make intrusive changes faster and confidently. In this talk, we’ll walk you through our prior art, challenges, learnings, and big benefits of typing our codebase.
This is the slide stack to the two JavaScript Operators YouTube videos at https://www.youtube.com/watch?v=4sF-9RqDxEA and https://www.youtube.com/watch?v=lRijlc3tsw0
Does what it says on the tin. An introduction to Modern Perl programming aimed at programmers who have little or no experience in Perl.
I gave this course at the London Perl Workshop in November 2013.
Called “downcase” on nil? Forgot to return the right object in one of your logic branches? Called “first” on a String instead of an Array and spent half an hour trying to figure out why a single character was getting passed around everywhere?
At Grailed, these situations were not uncommon. We are the largest marketplace for luxury men's fashion, with over 7 million users, and a growing Rails codebase that spans hundreds of thousands of lines. Before typing, changes to core interfaces often required creative grepping, modification of type checking unit tests, and updating brittle type documentation.
Ever since we started gradually typing our codebase with Sorbet, we’ve been able to make intrusive changes faster and confidently. In this talk, we’ll walk you through our prior art, challenges, learnings, and big benefits of typing our codebase.
In this session you learn about
1. How to download and install java in your PC
2, How to write simple Java Program
3. Operators in Java
4. Types of operators
i) Arithmetic operators
ii) Relational operators
iii) Logical operators
iv)Ternary operator
v) Bitwise operators
vi) Assignment operators
vii) Unary operators
viii) Special operators
5. Operators precedence
Lambda: A Peek Under The Hood - Brian GoetzJAX London
This is a *highly technical* session on the details of how Lambda expressions are implemented in the Java language, presented by Java Language Architect Brian Goetz
What is functional programming? This talk sets out to demystify the functional programming paradigm, debunk common myths, and reveal examples of why FP is advantageous compared to imperative programming.
A short description of Perly grammar processors leading up to Regexp::Grammars. Develops two R::G modules, one for single-line logfile entries, another for larger FASTA format entries in the NCBI "nr.gz" file. The second example shows how to derive one grammar from another by overriding tags in the base grammar.
We will study in depth, the Arduino program structure and we will learn more new terminologies used in the Arduino world. The Arduino software is open-source.
Presentation provides introduction and detailed explanation of the Java 8 Lambda and Streams. Lambda covers with Method references, default methods and Streams covers with stream operations,types of streams, collectors. Also streams are elaborated with parallel streams and benchmarking comparison of sequential and parallel streams.
Additional slides are covered with Optional, Splitators, certain projects based on lambda and streams
In this session you learn about
1. How to download and install java in your PC
2, How to write simple Java Program
3. Operators in Java
4. Types of operators
i) Arithmetic operators
ii) Relational operators
iii) Logical operators
iv)Ternary operator
v) Bitwise operators
vi) Assignment operators
vii) Unary operators
viii) Special operators
5. Operators precedence
Lambda: A Peek Under The Hood - Brian GoetzJAX London
This is a *highly technical* session on the details of how Lambda expressions are implemented in the Java language, presented by Java Language Architect Brian Goetz
What is functional programming? This talk sets out to demystify the functional programming paradigm, debunk common myths, and reveal examples of why FP is advantageous compared to imperative programming.
A short description of Perly grammar processors leading up to Regexp::Grammars. Develops two R::G modules, one for single-line logfile entries, another for larger FASTA format entries in the NCBI "nr.gz" file. The second example shows how to derive one grammar from another by overriding tags in the base grammar.
We will study in depth, the Arduino program structure and we will learn more new terminologies used in the Arduino world. The Arduino software is open-source.
Presentation provides introduction and detailed explanation of the Java 8 Lambda and Streams. Lambda covers with Method references, default methods and Streams covers with stream operations,types of streams, collectors. Also streams are elaborated with parallel streams and benchmarking comparison of sequential and parallel streams.
Additional slides are covered with Optional, Splitators, certain projects based on lambda and streams
SEO- How to measure its effectiveness, What Google Says and Resources requir...iexpertsforum
This presentation is an exhaustive description of SEO Process. It initially deals with the parameters which are relevant for measuring the effectiveness of SEO. This includes conditions like rankings, backlinks, bounce rate etc.
Further the presentation highlights Google’s views on SEO. This is an interesting part as it deals with how Google itself advises marketers to look out for SEO. Google also cautions marketers with the illegal practices related to SEO.
Finally the presentation talks about the resources and initiatives required to start with SEO, be it time, finance, tools etc.
Love it or hate it, JavaScript is playing an increasingly important role in the next generation of web and mobile apps. As code continues to move from the server to the client, JavaScript is being used to do more than simple HTML manipulation. Be prepared for this transition and make sure the JavaScript you write is optimized and ready to perform on desktops and devices! In this session, you will learn ten practical tips that you can use today to write faster, more maintainable, memory friendly JavaScript.
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.
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
Neuro-symbolic is not enough, we need neuro-*semantic*Frank van Harmelen
Neuro-symbolic (NeSy) AI is on the rise. However, simply machine learning on just any symbolic structure is not sufficient to really harvest the gains of NeSy. These will only be gained when the symbolic structures have an actual semantics. I give an operational definition of semantics as “predictable inference”.
All of this illustrated with link prediction over knowledge graphs, but the argument is general.
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.
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
91mobiles recently conducted a Smart TV Buyer Insights Survey in which we asked over 3,000 respondents about the TV they own, aspects they look at on a new TV, and their TV buying preferences.
Generating a custom Ruby SDK for your web service or Rails API using Smithyg2nightmarescribd
Have you ever wanted a Ruby client API to communicate with your web service? Smithy is a protocol-agnostic language for defining services and SDKs. Smithy Ruby is an implementation of Smithy that generates a Ruby SDK using a Smithy model. In this talk, we will explore Smithy and Smithy Ruby to learn how to generate custom feature-rich SDKs that can communicate with any web service, such as a Rails JSON API.
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualityInflectra
In this insightful webinar, Inflectra explores how artificial intelligence (AI) is transforming software development and testing. Discover how AI-powered tools are revolutionizing every stage of the software development lifecycle (SDLC), from design and prototyping to testing, deployment, and monitoring.
Learn about:
• The Future of Testing: How AI is shifting testing towards verification, analysis, and higher-level skills, while reducing repetitive tasks.
• Test Automation: How AI-powered test case generation, optimization, and self-healing tests are making testing more efficient and effective.
• Visual Testing: Explore the emerging capabilities of AI in visual testing and how it's set to revolutionize UI verification.
• Inflectra's AI Solutions: See demonstrations of Inflectra's cutting-edge AI tools like the ChatGPT plugin and Azure Open AI platform, designed to streamline your testing process.
Whether you're a developer, tester, or QA professional, this webinar will give you valuable insights into how AI is shaping the future of software delivery.
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on the notifications, alerts, and approval requests using Slack for Bonterra Impact Management. The solutions covered in this webinar can also be deployed for Microsoft Teams.
Interested in deploying notification automations for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
Are you looking to streamline your workflows and boost your projects’ efficiency? Do you find yourself searching for ways to add flexibility and control over your FME workflows? If so, you’re in the right place.
Join us for an insightful dive into the world of FME parameters, a critical element in optimizing workflow efficiency. This webinar marks the beginning of our three-part “Essentials of Automation” series. This first webinar is designed to equip you with the knowledge and skills to utilize parameters effectively: enhancing the flexibility, maintainability, and user control of your FME projects.
Here’s what you’ll gain:
- Essentials of FME Parameters: Understand the pivotal role of parameters, including Reader/Writer, Transformer, User, and FME Flow categories. Discover how they are the key to unlocking automation and optimization within your workflows.
- Practical Applications in FME Form: Delve into key user parameter types including choice, connections, and file URLs. Allow users to control how a workflow runs, making your workflows more reusable. Learn to import values and deliver the best user experience for your workflows while enhancing accuracy.
- Optimization Strategies in FME Flow: Explore the creation and strategic deployment of parameters in FME Flow, including the use of deployment and geometry parameters, to maximize workflow efficiency.
- Pro Tips for Success: Gain insights on parameterizing connections and leveraging new features like Conditional Visibility for clarity and simplicity.
We’ll wrap up with a glimpse into future webinars, followed by a Q&A session to address your specific questions surrounding this topic.
Don’t miss this opportunity to elevate your FME expertise and drive your projects to new heights of efficiency.
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
In today's fast-changing business world, Companies that adapt and embrace new ideas often need help to keep up with the competition. However, fostering a culture of innovation takes much work. It takes vision, leadership and willingness to take risks in the right proportion. Sachin Dev Duggal, co-founder of Builder.ai, has perfected the art of this balance, creating a company culture where creativity and growth are nurtured at each stage.
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...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.
4. Sources of
Misunderstanding
• The Name
• Mispositioning
• Design Errors
• Bad Implementations
• The Browser
• Bad Books
• Substandard Standard
• JavaScript is a Functional
5. History
• 1992
Oak, Gosling at Sun & FirstPerson
• 1995
HotJava
LiveScript, Eich at Netscape
• 1996
JScript at Microsoft
• 1998
6. Not a Web Toy
• It is a real language
• Small, but sophisticated
• It is not a subset of Java
7. Key Ideas
• Load and go delivery
• Loose typing
• Objects as general containers
• Prototypal inheritance
• Lambda
• Linkage though global variables
9. Numbers
• Only one number type
No integers
• 64-bit floating point
• IEEE-754 (aka “Double”)
• Does not map well to common
understanding of arithmetic:
• 0.1 + 0.2 = 0.30000000000000004
10. NaN
• Special number: Not a Number
• Result of undefined or erroneous
operations
• Toxic: any arithmetic operation
with NaN as an input will have NaN
as a result
• NaN is not equal to anything,
including NaN
11. Number function
Number(value)
• Converts the value into a number.
• It produces NaN if it has a problem.
• Similar to + prefix operator.
12. parseInt function
parseInt(value, 10)
• Converts the value into a number.
• It stops at the first non-digit character.
• The radix (10) should be required.
parseInt(quot;08quot;) === 0
13. Math
• Math object is modeled on Java's Math class.
• It contains
absolute value
abs
integer
floor
logarithm
log
maximum
max
raise to a power
pow
randomrandom number
nearest integer
round
sine
sin
14. Strings
• Sequence of 0 or more 16-bit
characters
UCS-2, not quite UTF-16
No awareness of surrogate pairs
• No separate character type
Characters are represented as strings with
a length of 1
• Strings are immutable
• Similar strings are equal ( == )
• String literals can use single or double
24. Dynamic Objects
• Unification of Object and Hashtable
• new Object() produces an empty container of
name/value pairs
• A name can be any string, a value can be any
value except undefined
• members can be accessed with dot notation or
subscript notation
• No hash nature is visible (no hash codes or
25. Loosely Typed
• Any of these types can be stored
in an variable, or passed as a
parameter to any function
• The language is not quot;untypedquot;
26. C
• JavaScript is syntactically a C
family language
• It differs from C mainly in its type
system, which allows functions to
be values
27. Identifiers
• Starts with a letter or _ or $
• Followed by zero or more letters, digits, _ or $
• By convention, all variables, parameters,
members, and function names start with lower
case
• Except for constructors which start with upper
case
• Initial _ should be reserved for
implementations
28. Reserved Words
abstract
boolean break byte
case catch char class const continue
debugger default delete do double
else enum export extends
false final finally float for function
goto
if implements import in instanceof int
interface
long
native new null
package private protected public
return
short static super switch synchronized
this throw throws transient true try typeof
var volatile void
while with
31. +
• Addition and concatenation
• If both operands are numbers,
then
add them
else
convert them both to strings
concatenate them
'$' + 3 + 4 = '$34'
32. +
• Unary operator can convert
strings to numbers
+quot;42quot; = 42
• Also
Number(quot;42quot;) = 42
• Also
parseInt(quot;42quot;, 10) = 42
+quot;3quot; + (+quot;4quot;) = 7
33. /
• Division of two integers can
produce a non-integer result
10 / 3 = 3.3333333333333335
34. == !=
• Equal and not equal
• These operators can do type
coercion
• It is better to use === and !==,
which do not do type coercion.
35. &&
• The guard operator, aka logical and
• If first operand is truthy
then result is second operand
else result is first operand
• It can be used to avoid null references
if (a) {
return a.member;
} else {
return a;
}
• can be written as
36. ||
• The default operator, aka logical or
• If first operand is truthy
then result is first operand
else result is second operand
• It can be used to fill in default values.
var last = input || nr_items;
• (If input is truthy, then last is input,
otherwise set last to nr_items.)
37. !
• Prefix logical not operator.
• If the operand is truthy, the result
is false. Otherwise, the result is
true.
• !! produces booleans.
38. Bitwise
& | ^ >> >>> <<
• The bitwise operators convert the
operand to a 32-bit signed integer,
and turn the result back into 64-
bit floating point.
39. Statements
• expression
• if
• switch
• while
• do
• for
• break
• continue
• return
• try/throw
40. Break statement
• Statements can have labels.
• Break statements can refer to those
labels.
loop: for (;;) {
...
if (...) {
break loop;
}
...
}
41. For statement
• Iterate through all of the elements
of an array:
for (var i = 0; i < array.length; i += 1) {
// within the loop,
// i is the index of the current member
// array[i] is the current element
}
42. For statement
• Iterate through all of the members of
an object:
for (var name in object) {
if (object.hasOwnProperty(name)) {
// within the loop,
// name is the key of current member
// object[name] is the current value
}
}
43. Switch statement
• Multiway branch
• The switch value does not need to
a number. It can be a string.
• The case values can be
expressions.
47. Try Statement
• The JavaScript implementation
can produce these exception
names:
'Error'
'EvalError'
'RangeError'
'SyntaxError'
'TypeError'
'URIError'
48. With statement
• Intended as a with (o) {
foo = null;
short-hand
}
• Ambiguous
o.foo = null;
• Error-prone foo = null;
• Don't use it
50. Var statement
• Defines variables within a
function.
• Types are not specified.
• Initial values are optional.
var name;
var nrErrors = 0;
51. Scope
• In JavaScript, {blocks} do not
have scope.
• Only functions have scope.
• Vars defined in a function are not
visible outside of the function.
52. Return statement
return expression;
• or
return;
• If there is no expression, then the
return value is undefined.
• Except for constructors, whose
default return value is this.
53. Objects
• Everything else is objects
• Objects can contain data and
methods
• Objects can inherit from other
objects.
54. Collections
• An object is an unordered collection of
name/value pairs
• Names are strings
• Values are any type, including other
objects
• Good for representing records and
trees
55. Object Literals
• Object literals are wrapped in { }
• Names can be names or strings
• Values can be expressions
• : separates names and values
• , separates pairs
• Object literals can be used anywhere a
56. Object Literals
var myObject = {name: quot;Jack B. Nimblequot;,
'goto': 'Jail', grade: 'A', level: 3};
quot;namequot; quot;Jack B. Nimblequot;
quot;gotoquot; quot;Jailquot;
quot;gradequot; quot;Aquot;
quot;levelquot; 3
var theName = myObject.name;
var destination = myObject['goto'];
57. Maker Function
function maker(name, where, grade, level) {
var it = {};
it.name = name;
it['goto'] = where;
it.grade = grade;
it.level = level;
return it;
}
myObject = maker(quot;Jack B. Nimblequot;,
'Jail', 'A', 3);
62. Object Augmentation
• New members can be added to
any object by simple assignment
• There is no need to define a new
class
myObject.format.colorModel =
'YCgCb';
myObject[name] = value;
63. Linkage
• Objects can be created with a secret
link to another object.
• If an attempt to access a name fails,
the secret linked object will be used.
• The secret link is not used when
storing. New members are only added
to the primary object.
• The object(o) function makes a new
64. Linkage
var myNewObject = object(myOldObject);
myNewObject
myOldObject
quot;namequot; quot;Jack B. Nimblequot;
quot;gotoquot; quot;Jailquot;
quot;gradequot; quot;Aquot;
quot;levelquot; 3
67. Prototypal Inheritance
• Some languages have classes,
methods, constructors, and modules.
JavaScript's functions do the work of
all of those.
• Instead of Classical Inheritance,
JavaScript has Prototypal Inheritance.
• It accomplishes the same things, but
differently.
• It offers greater expressive power.
68. Prototypal Inheritance
• Instead of organizing objects into rigid
classes, new objects can be made that are
similar to existing objects, and then
customized.
• Object customization is a lot less work than
making a class, and less overhead, too.
• One of the keys is the object(o) function.
• The other key is functions.
69. Object Methods
• All objects are linked directly or indirectly
to Object.prototype
• All objects inherit some basic methods.
• None of them are very useful.
• hasOwnProperty(name)
Is the name a true member of this
object?
• No copy method.
• No equals method.
70. Object Construction
• Make a new empty object
• All three of these expressions have
exactly the same result:
new Object()
{}
object(Object.prototype)
• {} is the preferred form.
71. Reference
• Objects can be passed as
arguments to functions, and can
be returned by functions
Objects are passed by reference.
Objects are not passed by value.
• The === operator compares object
references, not values
true only if both operands are the
72. Delete
• Members can be removed from an
object with the delete operator
delete myObject[name];
73. Arrays
• Array inherits from Object.
• Indexes are converted to strings and
used as names for retrieving values.
• Very efficient for sparse arrays.
• Not very efficient in most other cases.
• One advantage: No need to provide a
length or type when creating an array.
74. length
• Arrays, unlike objects, have a special
length member.
• It is always 1 larger than the highest
integer subscript.
• It allows use of the traditional for
statement.
for (i = 0; i < a.length; i += 1) {
...
}
75. Array Literals
• An array literal uses []
• It can contain any number of
expressions, separated by commas
myList = ['oats', 'peas', 'beans'];
• New items can be appended
myList[myList.length] = 'barley';
• The dot notation should not be used
with arrays.
• [] is preferred to new Array().
77. Deleting Elements
delete array[number]
• Removes the element, but leaves
a hole in the numbering.
array.splice(number, 1)
• Removes the element and
renumbers all the following
79. Arrays v Objects
• Use objects when the names are
arbitrary strings.
• Use arrays when the names are
sequential integers.
• Don't get confused by the term
Associative Array.
81. Arrays and Inheritance
• Don’t use arrays as prototypes.
The object produced this way does not have
array nature. It will inherit the array's values
and methods, but not its length.
• You can augment an individual array.
Assign a method to it.
This works because arrays are objects.
• You can augment all arrays.
82. Functions
• Functions are first-class objects
3. Functions can be passed,
returned, and stored just like any
other value
• Functions inherit from Object
and can store name/value pairs.
83. Function operator
• The function operator takes an
optional name, a parameter list,
and a block of statements, and
returns a function object.
function name(parameters) {
statements
}
• A function can appear anywhere
that an expression can appear.
84. lambda
• What JavaScript calls function,
other languages call lambda.
• It is a source of enormous
expressive power.
• Unlike most power-constructs, it
is secure.
85. Function statement
• The function statement is just a
short-hand for a var statement
with a function value.
function foo() {}
expands to
var foo = function foo() {};
86. Inner functions
• Functions do not all have to be
defined at the top level (or left
edge).
• Functions can be defined inside of
other functions.
87. Scope
• An inner function has access to
the variables and parameters of
functions that it is contained
within.
• This is known as Static Scoping
or Lexical Scoping.
88. Closure
• The scope that an inner function
enjoys continues even after the
parent functions have returned.
• This is called closure.
89. Example
function fade(id) {
var dom = document.getElementById(id),
level = 1;
function step () {
var h = level.toString(16);
dom.style.backgroundColor =
'#FFFF' + h + h;
if (level < 15) {
level += 1;
setTimeout(step, 100);
}
}
setTimeout(step, 100);
}
90. Function Objects
• Functions are objects, so they can
contain name/value pairs.
• This can serve the same purpose
as static members in other
languages.
91. Method
• Since functions are values,
functions can be stored in
objects.
• A function in an object is called a
method.
92. Invocation
• If a function is called with too
many arguments, the extra
arguments are ignored.
• If a function is called with too few
arguments, the missing values
will be undefined.
• There is no implicit type checking
93. Invocation
• There are four ways to call a function:
Function form
functionObject(arguments)
Method form
thisObject.methodName(arguments)
thisObject[quot;methodNamequot;](arguments)
Constructor form
new functionObject(arguments)
Apply form
functionObject.apply(thisObject,
94. Method form
thisObject.methodName(arguments)
• When a function is called in the
method form, this is set to
thisObject, the object containing
the function.
• This allows methods to have a
reference to the object of
95. Function form
functionObject(arguments)
• When a function is called in the
function form, this is set to the
global object.
That is not very useful.
It makes it harder to write helper
functions within a method because
the helper function does not get
access to the outer this.
96. Constructor form
new functionObject(arguments)
• When a function is called with the
new operator, a new object is
created and assigned to this.
• If there is not an explicit return
value, then this will be returned.
97. this
• this is an extra
Invocation
this
parameter. Its form
value depends on
the calling form. the global
function
object
• this gives
methods access method the object
to their objects.
the new
constructor
object
• this is bound at
98. arguments
• When a function is invoked, in addition
to its parameters, it also gets a special
parameter called arguments.
• It contains all of the arguments from
the invocation.
• It is an array-like object.
• arguments.length is the number of
99. Example
function sum() {
var i,
n = arguments.length,
total = 0;
for (i = 0; i < n; i += 1) {
total += arguments[i];
}
return total;
}
104. typeof
• The typeof prefix operator returns
a string identifying the type of a
value. type typeof
object 'object'
function 'function'
array 'object'
number 'number'
string 'string'
boolean 'boolean'
null 'object'
undefined 'undefined'
105. eval
eval(string)
• The eval function compiles and
executes a string and returns the
result.
• It is what the browser uses to convert
strings into actions.
• It is the most misused feature of the
language.
106. Function function
new Function(parameters, body)
• The Function constructor takes zero or
more parameter name strings, and a
body string, and uses the JavaScript
compiler to produce a function object.
• It should only be used to compile fresh
source from a server.
• It is closely related to eval.
107. Built-in Type Wrappers
• Java has int and Integer, two
incompatible types which can both
carry the same value with differing
levels of efficiency and
convenience.
• JavaScript copied this pattern to no
advantage. Avoid it.
• Avoid new Boolean()
• Avoid new String()
109. Augmentation
• We can directly modify individual
objects to give them just the
characteristics we want.
• We can do this without having to
create classes.
• We can then use our new object as the
prototype for lots of new objects, each
110. Working with the Grain
• Classical patterns are less
effective than prototypal patterns
or parasitic patterns.
• Formal classes are not needed for
reuse or extension.
111. (global) Object
• The object that dares not speak its
name.
• It is the container for all global
variables and all built-in objects.
• Sometimes this points to it.
var global = this;
• On browsers, window is the global
object.
112. Global variables are evil
• Functions within an application
can clobber each other.
• Cooperating applications can
clobber each other.
• Use of the global namespace
must be minimized.
113. Implied Global
• Any var which is not properly declared
is assumed to be global by default.
• This makes it easy for people who do
not know or care about encapsulation
to be productive, but it makes
applications less reliable.
• JSLint is a tool which helps identify
114. Namespace
• Every object is a separate namespace.
• Use an object to organize your
variables and functions.
• The YAHOO Object.
<head>
<script>
YAHOO={};
</script>
• http://twiki.corp.yahoo.com/view/Devel/TheYAHOOObject
115. Encapsulate
• Function scope can create an
encapsulation.
• Use an anonymous function to
wrap your application.
116. Example
YAHOO.Trivia = function () {
// define your common vars here
// define your common functions here
return {
getNextPoser: function (cat, diff) {
...
},
showPoser: function () {
...
}
};
} ();
117. Thinking about type
• Trading type-safety for dynamism.
• JavaScript has no cast operator.
• Reflection is really easy, and
usually unnecessary.
• Why inheritance?
Automatic casting
Code reuse
• Trading brittleness for flexibility.
119. RegExp
• Regular expression pattern
matcher
• Patterns are enclosed in slashes
• Example: a pattern that matches
regular expressions
//([^x00-x1f]|[([^x00-x1f]|
[^x00-x1f/])*]|[^x00-x1f/[])+/
[gim]*/
120. Threads
• The language definition is neutral on
threads
• Some language processors (like
SpiderMonkey) provide thread support
• Most application environments (like
browsers) do not provide it
122. ActionScript
• Empty strings are truthy
• keywords are case insensitive
• No Unicode support
• No RegExp
• No try
• No statement labels
• || and && return booleans
• separate operators for strings and
123. E4X
• Extensions to ECMAScript for XML
• Proposed by BEA
• Allows <XML> literals
• Not compatible with ECMAScript
Third Edition
• Not widely accepted yet
• Not in IE7
124. ECMAScript Fourth Edition
• A very large set of new features
are being considered.
• Mozilla and Opera are committed.
• It is not clear that Microsoft will
adopt it.
125. Style
• Programming style isn't about
personal taste.
• It is about rigor in expression.
• It is about clearness in
presentation.
• It is about product adaptability
and longevity.
• Good rules help us to keep the
126. Style and JavaScript
• Style is critically important for
JavaScript.
• The dynamic nature of the
language is considered by some
to be quot;too softquot;. Discipline is
necessary for balance.
• Most of the world's body of
127. Code Conventions for the
JavaScript Programming
Language
http://javascript.crockford.com/code.html
128. Semicolon insertion
• When the compiler sees an error, it
attempts to replace a nearby linefeed
with a semicolon and try again.
• This should alarm you.
• It can mask errors.
• Always use the full, correct forms,
129. Line Ending
• Break a line after a punctuator:
,.;:{}([=<>?!+-*/%
~ ^ | & == != <= >= += -= *= /= %=
^= |= &= << >> || && === !== <<= >>=
>>> >>>=
• Do not break after a name, string,
number, or ) ] ++ --
• Defense against copy/paste errors.
130. Comma
• Avoid tricky expressions using the
comma operators.
• Do not use extra commas in array
literals.
• Good: [1, 2, 3]
• Bad: [1, 2, 3,]
132. Forbidden Blocks
• Blocks do not have scope in JavaScript.
• Blocks should only be used with structured
statements
function
if
switch
while
for
do
try
133. Variables
• Define all variables at the
beginning of the function.
• JavaScript does not have block
scope, so their is no advantage in
declaring variables at the place of
their first use.
134. Expression Statements
• Any expression can be used as a
statement. That can mask errors.
• Only assignment expressions and
invocation expressions should be used
as statements.
• Good:
foo();
• Bad:
135. switch Statement
• Avoid using fallthrough.
• Each clause should explicitly
break or return or throw.
136. Assignment Expressions
• Do not use assignment
expressions in the condition parts
of if, while, or for.
• It is more likely that
if (a = b) { ... }
• was intended to be
if (a == b) { ... }
137. == and !=
• Be aware that == and != do type
coercion.
• Bad
if (a == null) { ... }
• Good:
if (a === null) { ... }
if (!a) { ... }
138. Labels
• Use labels only on these
statements:
do
for
switch
while
• Never use javascript: as a label.
139. JSLint
• JSLint can help improve the robustness
and portability of your programs.
• It enforces style rules.
• It can spot some errors that are very
difficult to find in debugging.
• It can help eliminate implied globals.
• Currently available on the web and as a
Konfabulator widget.
• Soon, in text editors and Eclipse.
140. UHOH!
• Universal Header Onerror Handler
• Inserted into 0.1% of pages
• Reports on JavaScript errors
• http://uhoh.corp.yahoo.com/
141. Key Ideas
• Load and go delivery
• Loose typing
• Objects as general containers
• Prototypal inheritance
• Lambda
• Linkage though global variables