This document discusses JavaScript functions. It explains that functions are first-class objects that can be stored in variables, passed as arguments, and returned from other functions. It provides examples of defining, calling, and returning values from functions. It also covers optional parameters, anonymous functions, higher-order functions, and functions as methods.
Currying and Partial Function Application (PFA)Dhaval Dalal
We look at Currying and Partial Function Application (PFA) in Functional Programming. Languages like Clojure don't have currying, but PFA, where has Haskell currying and not PFA, whereas Scala has both, Groovy wants you to call methods like curry() and rcurry(). In OO paradigm, we use DI (dependency Injection) and we will see how this is automatically subsumed using Currying and PFA.
Currying and Partial Function Application (PFA)Dhaval Dalal
We look at Currying and Partial Function Application (PFA) in Functional Programming. Languages like Clojure don't have currying, but PFA, where has Haskell currying and not PFA, whereas Scala has both, Groovy wants you to call methods like curry() and rcurry(). In OO paradigm, we use DI (dependency Injection) and we will see how this is automatically subsumed using Currying and PFA.
Object-Oriented JavaScript presentation given at the 2010 ESRI Developer Summit. Code and slides are also available at http://github.com/kvangork/OOJS-Presentation
Find me on twitter @kvangork
or my blog http://prng.vangorkom.org
Object-Oriented JavaScript presentation given at ESRI's 2010 Developer Summit. Slides and code available at http://github.com/kvangork/OOJS-Presentation
Find me on twitter @kvangork
or at my blog: http://prng.vangorkom.org
While Google is adding Kotlin as an official Android language, we're also expanding our research on this language. It’s developed by JetBrains, and the fact that these are the people behind a suite of IDEs, such as IntelliJ and ReSharper, really shines through in Kotlin. It’s pragmatic and concise and makes coding a satisfying and efficient experience.
Although Kotlin compiles to both JavaScript and soon machine code, I’ll focus on its prime environment, the JVM.
Please see my presentation to learn more!
Not so long ago Microsoft announced a new language trageting on front-end developers. Everybody's reaction was like: Why?!! Is it just Microsoft darting back to Google?!
So, why a new language? JavaScript has its bad parts. Mostly you can avoid them or workaraund. You can emulate class-based OOP style, modules, scoping and even run-time typing. But that is doomed to be clumsy. That's not in the language design. Google has pointed out these flaws, provided a new language and failed. Will the story of TypeScript be any different?
Sperasoft talks about several important aspects of ECMAScript6 - language widely used for client-side scripting on the web, in the form of several well-known implementations such as JavaScript, JScript and ActionScript.
Functional Programming for OO Programmers (part 2)Calvin Cheng
Code examples demonstrating Functional Programming concepts, with JavaScript and Haskell.
Part 1 can be found here - http://www.slideshare.net/calvinchengx/functional-programming-part01
Source code can be found here - http://github.com/calvinchengx/learnhaskell
Let me know if you spot any errors! Thank you! :-)
Object-Oriented JavaScript presentation given at the 2010 ESRI Developer Summit. Code and slides are also available at http://github.com/kvangork/OOJS-Presentation
Find me on twitter @kvangork
or my blog http://prng.vangorkom.org
Object-Oriented JavaScript presentation given at ESRI's 2010 Developer Summit. Slides and code available at http://github.com/kvangork/OOJS-Presentation
Find me on twitter @kvangork
or at my blog: http://prng.vangorkom.org
While Google is adding Kotlin as an official Android language, we're also expanding our research on this language. It’s developed by JetBrains, and the fact that these are the people behind a suite of IDEs, such as IntelliJ and ReSharper, really shines through in Kotlin. It’s pragmatic and concise and makes coding a satisfying and efficient experience.
Although Kotlin compiles to both JavaScript and soon machine code, I’ll focus on its prime environment, the JVM.
Please see my presentation to learn more!
Not so long ago Microsoft announced a new language trageting on front-end developers. Everybody's reaction was like: Why?!! Is it just Microsoft darting back to Google?!
So, why a new language? JavaScript has its bad parts. Mostly you can avoid them or workaraund. You can emulate class-based OOP style, modules, scoping and even run-time typing. But that is doomed to be clumsy. That's not in the language design. Google has pointed out these flaws, provided a new language and failed. Will the story of TypeScript be any different?
Sperasoft talks about several important aspects of ECMAScript6 - language widely used for client-side scripting on the web, in the form of several well-known implementations such as JavaScript, JScript and ActionScript.
Functional Programming for OO Programmers (part 2)Calvin Cheng
Code examples demonstrating Functional Programming concepts, with JavaScript and Haskell.
Part 1 can be found here - http://www.slideshare.net/calvinchengx/functional-programming-part01
Source code can be found here - http://github.com/calvinchengx/learnhaskell
Let me know if you spot any errors! Thank you! :-)
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...Hivelance Technology
Cryptocurrency trading bots are computer programs designed to automate buying, selling, and managing cryptocurrency transactions. These bots utilize advanced algorithms and machine learning techniques to analyze market data, identify trading opportunities, and execute trades on behalf of their users. By automating the decision-making process, crypto trading bots can react to market changes faster than human traders
Hivelance, a leading provider of cryptocurrency trading bot development services, stands out as the premier choice for crypto traders and developers. Hivelance boasts a team of seasoned cryptocurrency experts and software engineers who deeply understand the crypto market and the latest trends in automated trading, Hivelance leverages the latest technologies and tools in the industry, including advanced AI and machine learning algorithms, to create highly efficient and adaptable crypto trading bots
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisGlobus
JASMIN is the UK’s high-performance data analysis platform for environmental science, operated by STFC on behalf of the UK Natural Environment Research Council (NERC). In addition to its role in hosting the CEDA Archive (NERC’s long-term repository for climate, atmospheric science & Earth observation data in the UK), JASMIN provides a collaborative platform to a community of around 2,000 scientists in the UK and beyond, providing nearly 400 environmental science projects with working space, compute resources and tools to facilitate their work. High-performance data transfer into and out of JASMIN has always been a key feature, with many scientists bringing model outputs from supercomputers elsewhere in the UK, to analyse against observational or other model data in the CEDA Archive. A growing number of JASMIN users are now realising the benefits of using the Globus service to provide reliable and efficient data movement and other tasks in this and other contexts. Further use cases involve long-distance (intercontinental) transfers to and from JASMIN, and collecting results from a mobile atmospheric radar system, pushing data to JASMIN via a lightweight Globus deployment. We provide details of how Globus fits into our current infrastructure, our experience of the recent migration to GCSv5.4, and of our interest in developing use of the wider ecosystem of Globus services for the benefit of our user community.
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Anthony Dahanne
Les Buildpacks existent depuis plus de 10 ans ! D’abord, ils étaient utilisés pour détecter et construire une application avant de la déployer sur certains PaaS. Ensuite, nous avons pu créer des images Docker (OCI) avec leur dernière génération, les Cloud Native Buildpacks (CNCF en incubation). Sont-ils une bonne alternative au Dockerfile ? Que sont les buildpacks Paketo ? Quelles communautés les soutiennent et comment ?
Venez le découvrir lors de cette session ignite
Cyaniclab : Software Development Agency Portfolio.pdfCyanic lab
CyanicLab, an offshore custom software development company based in Sweden,India, Finland, is your go-to partner for startup development and innovative web design solutions. Our expert team specializes in crafting cutting-edge software tailored to meet the unique needs of startups and established enterprises alike. From conceptualization to execution, we offer comprehensive services including web and mobile app development, UI/UX design, and ongoing software maintenance. Ready to elevate your business? Contact CyanicLab today and let us propel your vision to success with our top-notch IT solutions.
Your Digital Assistant.
Making complex approach simple. Straightforward process saves time. No more waiting to connect with people that matter to you. Safety first is not a cliché - Securely protect information in cloud storage to prevent any third party from accessing data.
Would you rather make your visitors feel burdened by making them wait? Or choose VizMan for a stress-free experience? VizMan is an automated visitor management system that works for any industries not limited to factories, societies, government institutes, and warehouses. A new age contactless way of logging information of visitors, employees, packages, and vehicles. VizMan is a digital logbook so it deters unnecessary use of paper or space since there is no requirement of bundles of registers that is left to collect dust in a corner of a room. Visitor’s essential details, helps in scheduling meetings for visitors and employees, and assists in supervising the attendance of the employees. With VizMan, visitors don’t need to wait for hours in long queues. VizMan handles visitors with the value they deserve because we know time is important to you.
Feasible Features
One Subscription, Four Modules – Admin, Employee, Receptionist, and Gatekeeper ensures confidentiality and prevents data from being manipulated
User Friendly – can be easily used on Android, iOS, and Web Interface
Multiple Accessibility – Log in through any device from any place at any time
One app for all industries – a Visitor Management System that works for any organisation.
Stress-free Sign-up
Visitor is registered and checked-in by the Receptionist
Host gets a notification, where they opt to Approve the meeting
Host notifies the Receptionist of the end of the meeting
Visitor is checked-out by the Receptionist
Host enters notes and remarks of the meeting
Customizable Components
Scheduling Meetings – Host can invite visitors for meetings and also approve, reject and reschedule meetings
Single/Bulk invites – Invitations can be sent individually to a visitor or collectively to many visitors
VIP Visitors – Additional security of data for VIP visitors to avoid misuse of information
Courier Management – Keeps a check on deliveries like commodities being delivered in and out of establishments
Alerts & Notifications – Get notified on SMS, email, and application
Parking Management – Manage availability of parking space
Individual log-in – Every user has their own log-in id
Visitor/Meeting Analytics – Evaluate notes and remarks of the meeting stored in the system
Visitor Management System is a secure and user friendly database manager that records, filters, tracks the visitors to your organization.
"Secure Your Premises with VizMan (VMS) – Get It Now"
Why React Native as a Strategic Advantage for Startup Innovation.pdfayushiqss
Do you know that React Native is being increasingly adopted by startups as well as big companies in the mobile app development industry? Big names like Facebook, Instagram, and Pinterest have already integrated this robust open-source framework.
In fact, according to a report by Statista, the number of React Native developers has been steadily increasing over the years, reaching an estimated 1.9 million by the end of 2024. This means that the demand for this framework in the job market has been growing making it a valuable skill.
But what makes React Native so popular for mobile application development? It offers excellent cross-platform capabilities among other benefits. This way, with React Native, developers can write code once and run it on both iOS and Android devices thus saving time and resources leading to shorter development cycles hence faster time-to-market for your app.
Let’s take the example of a startup, which wanted to release their app on both iOS and Android at once. Through the use of React Native they managed to create an app and bring it into the market within a very short period. This helped them gain an advantage over their competitors because they had access to a large user base who were able to generate revenue quickly for them.
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I didn't get rich from it but it did have 63K downloads (powered possible tens of thousands of websites).
Strategies for Successful Data Migration Tools.pptxvarshanayak241
Data migration is a complex but essential task for organizations aiming to modernize their IT infrastructure and leverage new technologies. By understanding common challenges and implementing these strategies, businesses can achieve a successful migration with minimal disruption. Data Migration Tool like Ask On Data play a pivotal role in this journey, offering features that streamline the process, ensure data integrity, and maintain security. With the right approach and tools, organizations can turn the challenge of data migration into an opportunity for growth and innovation.
Large Language Models and the End of ProgrammingMatt Welsh
Talk by Matt Welsh at Craft Conference 2024 on the impact that Large Language Models will have on the future of software development. In this talk, I discuss the ways in which LLMs will impact the software industry, from replacing human software developers with AI, to replacing conventional software with models that perform reasoning, computation, and problem-solving.
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Globus
Large Language Models (LLMs) are currently the center of attention in the tech world, particularly for their potential to advance research. In this presentation, we'll explore a straightforward and effective method for quickly initiating inference runs on supercomputers using the vLLM tool with Globus Compute, specifically on the Polaris system at ALCF. We'll begin by briefly discussing the popularity and applications of LLMs in various fields. Following this, we will introduce the vLLM tool, and explain how it integrates with Globus Compute to efficiently manage LLM operations on Polaris. Attendees will learn the practical aspects of setting up and remotely triggering LLMs from local machines, focusing on ease of use and efficiency. This talk is ideal for researchers and practitioners looking to leverage the power of LLMs in their work, offering a clear guide to harnessing supercomputing resources for quick and effective LLM inference.
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?XfilesPro
Worried about document security while sharing them in Salesforce? Fret no more! Here are the top-notch security standards XfilesPro upholds to ensure strong security for your Salesforce documents while sharing with internal or external people.
To learn more, read the blog: https://www.xfilespro.com/how-does-xfilespro-make-document-sharing-secure-and-seamless-in-salesforce/
Designing for Privacy in Amazon Web ServicesKrzysztofKkol1
Data privacy is one of the most critical issues that businesses face. This presentation shares insights on the principles and best practices for ensuring the resilience and security of your workload.
Drawing on a real-life project from the HR industry, the various challenges will be demonstrated: data protection, self-healing, business continuity, security, and transparency of data processing. This systematized approach allowed to create a secure AWS cloud infrastructure that not only met strict compliance rules but also exceeded the client's expectations.
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Globus
The Earth System Grid Federation (ESGF) is a global network of data servers that archives and distributes the planet’s largest collection of Earth system model output for thousands of climate and environmental scientists worldwide. Many of these petabyte-scale data archives are located in proximity to large high-performance computing (HPC) or cloud computing resources, but the primary workflow for data users consists of transferring data, and applying computations on a different system. As a part of the ESGF 2.0 US project (funded by the United States Department of Energy Office of Science), we developed pre-defined data workflows, which can be run on-demand, capable of applying many data reduction and data analysis to the large ESGF data archives, transferring only the resultant analysis (ex. visualizations, smaller data files). In this talk, we will showcase a few of these workflows, highlighting how Globus Flows can be used for petabyte-scale climate analysis.
Experience our free, in-depth three-part Tendenci Platform Corporate Membership Management workshop series! In Session 1 on May 14th, 2024, we began with an Introduction and Setup, mastering the configuration of your Corporate Membership Module settings to establish membership types, applications, and more. Then, on May 16th, 2024, in Session 2, we focused on binding individual members to a Corporate Membership and Corporate Reps, teaching you how to add individual members and assign Corporate Representatives to manage dues, renewals, and associated members. Finally, on May 28th, 2024, in Session 3, we covered questions and concerns, addressing any queries or issues you may have.
For more Tendenci AMS events, check out www.tendenci.com/events
Advanced Flow Concepts Every Developer Should KnowPeter Caitens
Tim Combridge from Sensible Giraffe and Salesforce Ben presents some important tips that all developers should know when dealing with Flows in Salesforce.
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...informapgpstrackings
Keep tabs on your field staff effortlessly with Informap Technology Centre LLC. Real-time tracking, task assignment, and smart features for efficient management. Request a live demo today!
For more details, visit us : https://informapuae.com/field-staff-tracking/
Check out the webinar slides to learn more about how XfilesPro transforms Salesforce document management by leveraging its world-class applications. For more details, please connect with sales@xfilespro.com
If you want to watch the on-demand webinar, please click here: https://www.xfilespro.com/webinars/salesforce-document-management-2-0-smarter-faster-better/
1. CSE 341
Lecture 25
More about JavaScript functions
slides created by Marty Stepp
http://www.cs.washington.edu/341/
2. 2
First-class functions
• JS functions are first-class objects. You can:
store a (reference to a) function in a variable
create an array of functions
use a function as a property of an object (a method)
pass a function as a parameter; return a function
write functions that take varying numbers of parameters
write higher-order functions (that take others as params)
define functions inside functions (nested functions)
define anonymous functions (lambdas)
store properties inside functions
3. 3
Defining a function
function name(paramName, ..., paramName) {
statements;
}
• example:
function sumTo(n) {
var sum = 0;
for (var i = 1; i <= n; i++) {
sum += i;
}
return sum;
}
4. 4
Returning values
function maybeReturn(n) {
if (n % 2 == 0) {
return "even";
}
// else return undefined
}
• parameter and return types are not declared
the function can return anything it wants
if a function returns nothing, it returns undefined
a function can sometimes return values and sometimes not
5. 5
Calling a function
functionName(expr, ..., expr)
• example:
sumTo(6) // returns 21
• extra parameters passed are ignored:
sumTo(3, "hello", null, 42) // returns 6
• expected parameters not passed are undefined :
sumTo() // returns 0
6. 6
Optional parameters
function greet(name, msg) {
if (typeof(msg) === "undefined") {
msg = "Hello";
}
print(msg + " to you, " + name);
}
> greet("Bob", "Good day");
Good day to you, Bob
> greet("Sue");
Hello to you, Sue
to have an optional parameter, check whether it is defined
7. 7
Object as argument specifier
function mealCost(argObj) {
var amt = argObj["subtotal"];
if (argObj["tax"]) { amt *= 1 + argObj["tax"]; }
if (argObj["tip"]) { amt *= 1 + argObj["tip"]; }
if (argObj["donation"]) { amt += argObj["donation"]; }
return amt;
}
> mealCost({subtotal: 50.0, tip: .15})
57.5
> mealCost({subtotal: 10.0, tax: .08, donation: true})
11.8
specify many parameters as properties of a single object
– can pass many args in any order; optional args; clear naming
– this style is seen in JavaScript libraries (jQuery, Prototype)
8. 8
Variadic functions (var-args)
function addAll() {
var sum = 0;
for (var i = 0; i < arguments.length; i++) {
sum += arguments[i];
}
return sum;
}
addAll(1, 7, 4, 3) returns 15
addAll(1, 2, "3", 4, 5) returns "3345"
• each function has an array property* named arguments
that stores all parameter values passed to it
can be used to create variadic (var-args) functions
* actually a duck-typed array-like object with a length field
9. 9
Anonymous functions (lambdas)
function(paramName, ..., paramName) {
statements;
}
• anonymous functions can be stored, passed, returned
> function foo(x, f) { return f(x) + 1; }
> foo(5, function(n) { return n * n; })
26
• Exercise: Sort an array of strings case-insensitively.
• Exercise: Sort an array of names by last, then first, name.
10. 10
Two ways to declare a function
• The following are equivalent:
function name(params) { var name = function(params) {
statements; statements;
} }
var squared = function(x) {
return x*x;
};
11. 11
Array higher-order functions *
* most web browsers are missing some/all of these methods
.every(function) accepts a function that returns a boolean value
and calls it on each element until it returns false
.filter(function) accepts a function that returns a boolean; calls it
on each element, returning a new array of the
elements for which the function returned true
.forEach(function) applies a "void" function to each element
.map(function) applies function to each element; returns new array
.reduce(function)
.reduce(function,
initialValue)
.reduceRight(function)
.reduceRight(function,
initialValue)
accepts a function that accepts pairs of values and
combines them into a single value; calls it on each
element starting from the front, using the given
initialValue (or element [0] if not passed)
reduceRight starts from the end of the array
.some(function) accepts a function that returns a boolean value
and applies it to each element until it returns true
12. 12
Higher-order functions in action
> var a = [1, 2, 3, 4, 5];
> a.map(function(x) { return x*x; })
1,4,9,16,25
> a.filter(function(x) { return x % 2 == 0; })
2,4
• Exercise: Given an array of strings, produce a new array that
contains only the capitalized versions of the strings that contained
5 or more letters.
13. 13
Nested functions
// adds 1 to each element of an array of numbers
function incrementAll(a) {
function increment(n) { return n + 1; }
var result = a.map(increment);
return result;
}
• functions can be declared inside of other functions
the scope of the inner function is only within the outer one
14. 14
Invocation patterns
• functions can be invoked in four ways in JavaScript:
as a normal function
as a method of an object
as a constructor
through their apply property
15. 15
Functions as methods
• an object's methods are just properties that are functions
the function uses the this keyword to refer to the object
> var teacher = {
name: "Tyler Durden",
salary: 0.25,
greet: function(you) {
print("Hi " + you + ", I'm " + this.name);
},
toString: function() {
return "Prof. " + this.name;
}
};
> teacher.greet("kids");
Hi kids, I'm Tyler Durden
16. 16
Function binding
{ ...
propertyName: function, // bind at
... // declaration
}
object.propertyName = function; // bind later
• when a function is stored as a property of an object, a
copy of that function is bound to the object
calling the function through that object will cause that
object to be used as this during that particular call
if you don't call the function through the object, that
object won't be used as this
17. 17
The this keyword
function printMe() {
print("I am " + this);
}
> teacher.print = printMe;
> teacher.print();
I am Prof. Tyler Durden
> printMe();
I am [object global]
> ({p: printMe}).p()
I am [object Object]
> var temp = teacher.print;
> temp();
I am [object global]
18. 18
Aside: Web event handlers
<button id="b1">Click Me</button> HTML
var b1 = document.getElementById("b1"); JS
b1.onclick = function() { ... };
• most JavaScript code in web pages is event-driven
elements in the HTML have events that can be handled
you specify a JS function to run when the event occurs
the function can access/modify the page's appearance
19. 19
Invoking with apply
func.apply(thisObj, arguments);
• You can call a function using its apply property
allows you to set this to be anything you want
allows you to pass a function its arguments as an array
var o = ({toString: function(){return "!"}});
> apply(printMe, o, []);
I am !
Exercise: Write a function callBoth that takes two functions
and an array of parameters and calls both, passing them
those parameters, and printing both results.
20. 20
Composing functions
function compose(f, g) {
return function() {
return f(g.apply(this, arguments));
};
}
• JavaScript has no built-in syntax for composing functions
but you can use apply to write a helper for composition
21. 21
How to curry functions
function toArray(a, i) { // converts a
var result = [], i = i || 0; // duck-typed obj
while (i < a.length) { // into an array
result.push(a[i++]);
}
return result;
};
function curry(f) { // Usage: curry(f, arg1, ...)
var args = toArray(arguments, 1); // remove f
return function() {
return f.apply(this,
args.concat(toArray(arguments)));
};
}
• JavaScript doesn't include syntax for currying functions
but we can add such functionality ourselves
22. 22
Methods of Function objects
.toString() string representation of function (its code, usually)
.apply(this, args) calls a function using the given object as this and
passing the given array of values as its parameters
.call(this, arg1, ...) var-args version of apply; pass args without array
.bind(this) attaches the function's this reference to given obj