SlideShare a Scribd company logo
1 of 96
Download to read offline
www.ktrick.com
A-3
Javascript OOP for XPages Developers
Kazunori Tatsuki @ Ktrick Co,. Ltd.
• Name: Kazunori Tatsuki
• Company: KTrick Co,. Ltd.
• Title: Owner of KTrick Co,. Ltd.
• My Experience:
- 7 years development experience as IBM Vender in US.
- XPages and all other domino related languages, C, C++,
Objective-C, Java, PHP etc.
Introduction
Are you struggling with developing
XPages application?
Why?
Javascript?
Client side Javascript…
Sever side Javascript…
What’s different?
Nowadays Javascript sample code is like this …
var func1 = function(){
alert("hello!");
}
var myButton = new Button({
label: "Show me!",
onClick: function(){
myDialog.set("content", “Hello!");
myDialog.show();
}
}, "progbutton").startup();
Javascript used to be like this…
function func1(param){
alert( param);
}
It is easier to understand, isn’t it?
Why has it changed?
Have you ever seen this?
( function() {
//contents here…
}() );
Hmmm, Too much parenthesis…
Actually these are all different meaning.
Javascript looks complicated.
but
Don’t give up!
In this session,
I would like you to understand the structure of
Javascript by breaking down the source code one by one.
Object Oriented Programming
What’s the benefits of using OOP?
Benefits of OOP
・Reusability
・ Refactoring
・ Extensibility
・ Maintenance
・ Efficiency
As a result,
you can reduce the time and cost for development and testing.
OOP
What do you imagine from this word?
OOP
Class
Delegate
OverloadPolymorphism
Java
C++
Abstract
class
C#
Override
Inheritance
Derived class
Instance
UML
If you already have OOP experience, you may think of
「 Class 」
Is there class in Javascript?
Nope
How can we develop OOP without class?
The answer is…
Prototype Chain !!
To begin with, Javascript only has
Object.
sub Class (type)
By the way, Class is like this…
Super Class (type)
Object (Instance)
Object (Instance)
Object (Instance)
NEW
NEW
NEW
Class is like ‘type’.
You define the class as the
abstract type for instance. Then
you can generate the instances
from the classes.
By doing this, you can generate
same type objects (instances)
easily ,which have the same
functions and attributes.
Again, Javascript doesn’t have Class structure…
then…
Javascript Prototype chain is like this…
Object (Instance)
Object (Instance)
Object (Instance)
Object (Instance)
Dele
gate
Dele
gate
Dele
gate
You can connect the objects
and objects like chain.
Then if the original object
doesn’t have the specific
methods or variables, then
Javascript delegates to search
in the other object until they
are found.
Object (Instance)
Dele
gate
Let’s take a look at the actual source code.
※Basically please consider that the sample codes are written in client side Javascript
because server side Javascript cannot use some methods like alert().
However the theories and structures are the same!
Basic lesson.
How to generate Object?
var obj = { };
That’s it. An empty object was generated.
Object structure
var obj = {
key: value
};
Object can have Properties
(the set of Key and value)
That’s it!
var obj = {
name : “Apple”,
size : 500
};
alert(obj.name);
(i.e.)
var obj = {
func1 : function( ) {alert(“hoge”); }
};
obj.func1(); // Output is “hoge”
In Javascript, even the method is a “value”
var func = function( ){};
A method is a value,
therefore you can set it to
a variable.
Of course, you can
operate variables as usual.
(i.e) You can set the method to object
property.
Finally, explanation of Prototype Chain !!
It’s THE Javascript OOP
There are two important keywords below when learning
Javascript Prototype Chain.
➲ __proto__ ➲prototype
It’s very important to understand what is different from each other
to understand Javascript OOP.
➲ __proto__
__proto__
・[Rule] All objects in Javascript have [[Prototype]] internally.
However some browser application like Chrome, Firefox etc allow
you to access the [[Prototype]] by using __proto__ property
instead.
Internal means that you basically
cannot access to the [[Prototype]]
Like this…
Object (Instance)
Object (Instance)
Object (Instance)
Object (Instance)
Dele
gate
Dele
gate
Dele
gate
__proto__
__proto__
__proto__
__proto__
Sample code (This sample code works in Chrome & Firefox since allowing you to access by
using “__proto__” )
However this code
alert “It is Apple”
var obj = {
name : “none”,
callMe : function() { alert(“It is ” + this.name); }
};
var objApple = { name : “Apple”};
objApple.__proto__ = obj;
var objBlackbox = { };
objBlackbox.__proto__ = objApple;
objBlackbox.callMe();
Object is empty…
Confirm the order of source code(1)
It alerts “It is Apple”
Generates object named obj.
It has name and callMe
property.
Generates object named objApple.
name property is ”Apple”.
Generates object named
objBlackbox.
There is no property.
var obj = {
name : “none”,
callMe : function() { alert(“It is ” + this.name); }
};
var objApple = { name : “Apple”};
objApple.__proto__ = obj;
var objBlackbox = { };
objBlackbox.__proto__ = objApple;
objBlackbox.callMe();
Confirm the order of source code (2)
Set “obj” into
objApple.__proto_
var obj = {
name : “none”,
callMe : function() { alert(“It is ” + this.name); }
};
var objApple = { name : “Apple”};
objApple.__proto__ = obj;
var objBlackbox = { };
objBlackbox.__proto__ = objApple;
objBlackbox.callMe();
Generate object named obj.
It has name and callMe
property.
Generate object named objApple.
name property is ”Apple”.
Generate object named
objBlackbox.
There is no property.
Set “objApple” int
objBlackbox.__proto__
var obj = {
name : “none”,
callMe : function() { alert(“It is ” + this.name); }
};
var objApple = { name : “Apple”};
objApple.__proto__ = obj;
var objBlackbox = { };
objBlackbox.__proto__ = objApple;
objBlackbox.callMe();
Set “obj” into
objApple.__proto_
Generate object named obj.
It has name and callMe
property.
Generate object named objApple.
name property is ”Apple”.
Generate object named
objBlackbox.
There is no property.
Confirm the order of source code (3)
Confirm the method call (1)
var obj = {
name : “none”,
callMe : function() { alert(“It is ” + this.name); }
};
var objApple = { name : “Apple”};
objApple.__proto__ = obj;
var objBlackbox = { };
objBlackbox.__proto__ = objApple;
objBlackbox.callMe();
(1) There is no callMe()
method in objBlackbox
var obj = {
name : “none”,
callMe : function() { alert(“It is ” + this.name); }
};
var objApple = { name : “Apple”};
objApple.__proto__ = obj;
var objBlackbox = { };
objBlackbox.__proto__ = objApple;
objBlackbox.callMe();
Confirm the method call (2)
(2)Search object stored in __proto__ (objApple)
var obj = {
name : “none”,
callMe : function() { alert(“It is ” + this.name); }
};
var objApple = { name : “Apple”};
objApple.__proto__ = obj;
var objBlackbox = { };
objBlackbox.__proto__ = objApple;
objBlackbox.callMe();
Confirm the method call (3)
(1) There is no callMe()
method in objBlackbox
(3) There is no callMe()
method in objApple neither.
var obj = {
name : “none”,
callMe : function() { alert(“It is ” + this.name); }
};
var objApple = { name : “Apple”};
objApple.__proto__ = obj;
var objBlackbox = { };
objBlackbox.__proto__ = objApple;
objBlackbox.callMe();
(2)Search object stored in __proto__ (objApple)
(1) There is no callMe()
method in objBlackbox
Confirm the method call (4)
(4) Serach object stored in __proto__ (obj)
var obj = {
name : “none”,
callMe : function() { alert(“It is ” + this.name); }
};
var objApple = { name : “Apple”};
objApple.__proto__ = obj;
var objBlackbox = { };
objBlackbox.__proto__ = objApple;
objBlackbox.callMe();
Confirm the method call (5)
(3) There is no callMe()
method in objApple neither.
(2)Search object stored in __proto__ (objApple)
(1) There is no callMe()
method in objBlackbox
(5) Found callMe() method in obj!var obj = {
name : “none”,
callMe : function() { alert(“It is ” + this.name); }
};
var objApple = { name : “Apple”};
objApple.__proto__ = obj;
var objBlackbox = { };
objBlackbox.__proto__ = objApple;
objBlackbox.callMe();
(4) Serach object stored in __proto__ (obj)
Confirm the method call (6)
(3) There is no callMe()
method in objApple neither.
(2)Search object stored in __proto__ (objApple)
(1) There is no callMe()
method in objBlackbox
(1) callMe() method is called.
var obj = {
name : “none”,
callMe : function() { alert(“It is ” + this.name); }
};
var objApple = { name : “Apple”};
objApple.__proto__ = obj;
var objBlackbox = { };
objBlackbox.__proto__ = objApple;
objBlackbox.callMe();
Confirm the attribute call (1)
(2) Refer “name” property
※”this” means “object itself.”
var obj = {
name : “none”,
callMe : function() { alert(“It is ” + this.name); }
};
var objApple = { name : “Apple”};
objApple.__proto__ = obj;
var objBlackbox = { };
objBlackbox.__proto__ = objApple;
objBlackbox.callMe();
Confirm the attribute call (2)
(1) callMe() method is called.
(3) There is no “name”
property in objBlackbox
var obj = {
name : “none”,
callMe : function() { alert(“It is ” + this.name); }
};
var objApple = { name : “Apple”};
objApple.__proto__ = obj;
var objBlackbox = { };
objBlackbox.__proto__ = objApple;
objBlackbox.callMe();
(2) Refer “name” property
※”this” means “object itself.”
Confirm the attribute call (3)
(1) callMe() method is called.
(4) Search the object stored in __proto__ (objApple)
var obj = {
name : “none”,
callMe : function() { alert(“It is ” + this.name); }
};
var objApple = { name : “Apple”};
objApple.__proto__ = obj;
var objBlackbox = { };
objBlackbox.__proto__ = objApple;
objBlackbox.callMe();
(3) There is no “name”
property in objBlackbox
(2) Refer “name” property
※”this” means “object itself.”
Confirm the attribute call (4)
(1) callMe() method is called.
(5) Found ”name“ in objApple !
var obj = {
name : “none”,
callMe : function() { alert(“It is ” + this.name); }
};
var objApple = { name : “Apple”};
objApple.__proto__ = obj;
var objBlackbox = { };
objBlackbox.__proto__ = objApple;
objBlackbox.callMe();
(4) Search the object stored in __proto__ (objApple)
(3) There is no “name”
property in objBlackbox
(2) Refer “name” property
※”this” means “object itself.”
Confirm the attribute call (5)
(1) callMe() method is called.
(6) There is “name” property in obj as
well. However not referred
var obj = {
name : “none”,
callMe : function() { alert(“It is ” + this.name); }
};
var objApple = { name : “Apple”};
objApple.__proto__ = obj;
var objBlackbox = { };
objBlackbox.__proto__ = objApple;
objBlackbox.callMe();
(5) Found ”name“ in objApple !
(4) Search the object stored in __proto__ (objApple)
(3) There is no “name”
property in objBlackbox
(2) Refer “name” property
※”this” means “object itself.”
Confirm the attribute call (6)
(1) callMe() method is called.
Like in the sample code, if the
original object does not have the
methods or attributes, then
Javascript delegates to the chained
object to search them via __proto__
until found
This is
Prototype Chain !
Object (Instance)
Object (Instance)
Object (Instance)
Object (Instance)
Dele
gate
Dele
gate
Dele
gate
Not
Found
Found
Not
Found
Not
Found
Now is it ok to understand __proto__ ?
Wait a minutes…
__proto__ (aka [[Prototype]]) is just internal property.
Then we should not use the code like below...
objApple.__proto__ = obj;
Is it true?
Yes, Do not use it!
In fact I used the code like below as an example so that I can explain
the internal mechanism more clearly.
However, there is an alternative way to achieve the same logic.
var objApple = { name : “Apple”};
objApple.__proto__ = obj;
The answer is using “New” operation
(i.e.)This is the sample code equivalent to the previous sample.
var obj = new Frout(“Apple”);
Breakdown
of this code
later on.
var Frout = function( pname ) {
this.name = pname;
}
Frout.prototype.callMe = function() { alert(“It is ” + this.name); };
var objApple = new Frout(“Apple”);
➲ prototype
Before moving forward, there is an another keyword
called ”prototype”
It’s very important to understand what is different from __proto__!
prototype
・[Rule] All function objects have prototype property.
“function object”
Hmm, New keyword again...
But don’t worry. You already know this.
Function Object is like this…
It was already explained in previous slide.
Function(method) can be value.
var func = function( ){};
All Function Objects have prototype property.
Again,
For example,
var func = function( ){};
alert( func.prototype );
The second line above does not output “undefined”. This means prototype exists as the default.
However after defining the function object, the prototype refer just empty object.
Then, How to use prototype?
The answer is…
Prototype is used with new operation when the object is generated!
Confirm by source code
(This is the sample code equivalent to previous sample for __proto__)
Define Constructor
Generates Function Object.
name is undefined at this
moment.
Set the method to the
prototype property of Frout
object.
Generate objApple object by
using new operation.
By the prototype chain,
objApple can call the callMe()
method of Frout prototype
var Frout = function( pname ) {
this.name = pname;
}
Frout.prototype.callMe = function() { alert(“It is ” + this.name); };
var objApple = new Frout(“Apple”);
objApple.callMe(); Alert 「It is Apple」
※ it is not
“objApple.prototype.callMe() “
Explain in the
next slide
var obj = {};
obj.__proto__ = Frout.prototype;
Frout.apply(obj, arguments );
return obj;
Try to breakdown the process of new operation artificially.
var objApple = new Frout(“Apple”);
var obj = {};
obj.__proto__ = Frout.prototype;
Frout.apply(obj, arguments );
return obj;
(1) Generates object.
var objApple = new Frout(“Apple”);
Try to breakdown the process of new operation artificially.
var obj = {};
obj.__proto__ = Frout.prototype;
Frout.apply(obj, arguments );
return obj;
(2) Set prototype property into __proto__.
Frout.prototype
Has callMe()
method.
Frout.prototype.callMe = function() { alert(“It is ” + this.name); };
var objApple = new Frout(“Apple”);
Try to breakdown the process of new operation artificially.
(1) Generate object.
var obj = {};
obj.__proto__ = Frout.prototype;
Frout.apply(obj, arguments );
return obj;
(3) Execute constructor function.
Constructor
function is
executed only
when function
object is
generated.
Frout.prototype.callMe = function() { alert(“It is ” + this.name); };
var objApple = new Frout(“Apple”);
Try to breakdown the process of new operation artificially.
(2) Set prototype property into __proto__.
Frout.prototype
Has callMe()
method.
(1) Generate object.
var obj = {};
obj.__proto__ = Frout.prototype;
Frout.apply(obj, arguments );
return obj; (4) Returns the object.
Frout.prototype.callMe = function() { alert(“It is ” + this.name); };
var objApple = new Frout(“Apple”);
Try to breakdown the process of new operation artificially.
(3) Execute constructor function.
Constructor
function is
executed only
when function
object is
generated.
(2) Set prototype property into __proto__.
Frout.prototype
Has callMe()
method.
(1) Generate object.
var obj = {};
obj.__proto__ = Frout.prototype;
Frout.apply(obj, arguments );
return obj;
Frout.prototype.callMe = function() { alert(“It is ” + this.name); };
var objApple = new Frout(“Apple”);
var objApple = new Frout(“Apple”);
Try to breakdown the process of new operation artificially.
(4) Return the object.
(3) Execute constructor function.
Constructor
function is
executed only
when function
object is
generated.
(2) Set prototype property into __proto__.
Frout.prototype
Has callMe()
method.
(1) Generate object.
The sample code using for
explanation of __proto__
var obj = {};
obj.__proto__ = Frout.prototype;
Frout.apply(obj, arguments );
return obj;
The breakdown process of new
operation artificially.
If you replace obj to Frout.prototype,
then both objects have callMe()
Frout.prototype.callMe = function() {…};
var obj = {
name : “none”,
callMe : function() { … }
};
var objApple = { name : “Apple”};
objApple.__proto__ = obj;
Difference between __proto__ and prototype
Prototype is used when
object is generated by
new operation to be
stored in __proto__.
Used by prototype
search mechanism
internally.
By the new operation,
object prototype is
automatically stored.
__proto__ prototype
To make a
prototype chain,
use this prototype.
__proto__ is just needed
to understand the internal
mechanism.
Use new and prototype for
OOP.
So, a little Brain Teaser
Frout object preparation
and if we describe
We don’t want to write this, correct? It is not useful
var Frout = function( name ) {
this.name = name;
}
Frout.prototype.callMe = function() { alert(“It is ” + this.name); };
var Frout = function( name ) {
this.name = name;
this.callMe = function() { alert(“It is ” + this.name); };
}
From an OOP perspective this is bad
But let’s continue…
The reason:
var Frout = function( name ) {
this.name = name;
this.callMe = function() { alert(“It is ” + this.name); };
}
In this code, without a prototype, it will be defined inside the constructor
In other words:
Everytime new is called to create this object, callMe is also instantiated.
In Contrast, methods defined in the prototype, falls within the prototype chain inconsistently
Memory efficiency is better because the mechanism allows reference to the same memory when new objects are
created.
Frout.prototype.callMe = function() { alert(“It is ” + this.name); };
Practical Use
From the sample code earlier:
This function of brackets is integral to what kind of work?
( function() {
//code
}() );
Arriving at the conclusion
Calling an anonymous function immediately
We are going to do this
Immediately after the function
object is returned, we're calling
the function.
Create function
Object。
( function() {
//code・・・
}() );
Anonymous funtion
with no variable
This was done through a very complicated process。
This is used as such that when the page is loaded, it processes only once。
There are 2 parts?
//Immediate function1
(function () {
//code・・・
}());
//Immediate function2
(function () {
//code・・・
})();
Both are immediate function. In
JSLint(http://www.jslint.com/) the
former code seems to be preferred
Practical Use 2…
the result…
var Frout = function( name ) {
this.name = name;
}
Frout.prototype.callMe = function() { alert(“It is ” + this.name); };
var objApple = new Frout(“Apple”);
alert( objApple.name );
You should not be
able see if it was
private variable
Is this a
private variable?
protected variable?
public variable?
To be considered OOP, don’t we want to hide the private variable?
(Naturally)we are able to see orz
but wait a minute…
I modified something like this
var FroutModel = (function() {
// private variable
var name = “none";
// Constructor
var cls = function(pname){name = pname;};
// public method
cls.prototype.callMe = function() {alert("This is "+name);};
return cls;
} () );
var Frout = function( name ) {
this.name = name;
}
Frout.prototype.callMe = function() { alert(“It is ” + this.name); };
Before re edit
var FroutModel = (function() {
// private variable
var name = “none";
// Constructor
var cls = function(pname){name = pname;};
// public method
cls.prototype.callMe = function() {alert("This is "+name);};
return cls;
} () );
var objApple = new FroutModel(“Apple”);
alert( objApple.name );
objApple.callMe();
To make sure that
undefined is hidden
Can be
successfully called
Somehow it very much looks like a class
In addition to class inheritance, you can implement like this:
var FroutModel = (function() {
// private variable
var name = “none";
// Constructor
var cls = function(pname){name = pname;};
// Parent class inheritance
cls.prototype = new BaseModel();
// public method
cls.prototype.callMe = function() {alert("This is "+name);};
return cls;
} () );
Like this:
BaseModel object and
FroutModel object are
doing the same
implementation
Below are some descriptions about the code up to now. Please challenge yourself by solving the
puzzle
var FroutModel = (function() {
// private variable
var name = “none";
// constructor
var cls = function(pname){name = pname;};
// parent class inheritance
cls.prototype = new BaseModel();
// public method
cls.prototype.callMe = function() {alert("This is "+name);};
return cls;
} () );
Hint: Scope chain cannot be seen
from the outside
Hint:Generate another
object inside the FroutModel
function
Hint: Returns the object that
was generated in the
FroutModel
Hint: Immediate
function
This time、
XPages discussion has not even come out yet…
Now, Javascript has two types:
Client-side Javascript
Server-side Javascript
Both have the concept of class
Lets try the last class’s implementation of SSJS. It’s also useful to copy to script lib
var AppModel = (function() {
// private variable
var name = “none";
// constructor
var cls = function(pname){name = pname;};
// parent class inheritance
cls.prototype = new BaseModel();
// public method
cls.prototype.func1 = function() {…};
return cls;
} () );
Actually、the
Javascript structure
has their own OOP
template, which I
don’t like.
Cut paste to script library
Xpages call から呼び出し
Output Result
Storing the new object
using viewScope
Some notes when using OOP in XPages
Previously, we have stored the new object into viewScope. In order to use objects persistently, choose “Save the page in
memory” at the XSP property setting
What do you think so far?
In order to better understand Object-oriented in
Javascript, I think it is best to try various concept
I prepared an HTML file for you to test 
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
// <![CDATA[
var FroutModel = (function() {
// private variable
var name = "hoge";
// コンストラクタ
var cls = function(pname){name = pname;};
// メソッド
cls.prototype.callMe = function() {alert("This is "+name);};
return cls;
}());
var frt = new FroutModel("Banana");
frt.callMe();
alert("frout.name="+frt.name);
// ]]>
</script>
</head>
<body>
</body>
</html>
Note that we are no longer afraid of Dojo
and jQuery
R
e
f
e
r
e
n
c
e
s
• 最強オブジェクト指向言語 JavaScript 再入門
Yuji Nojima slides. Developer at Foreignkey, Co. Ltd.
http://www.slideshare.net/yuka2py/javascript-23768378
• ブログ XPagesで行こう!
Kenji Ebihara’s blog. IBM Champion. Ricoh IT Solution
https://www.ibm.com/developerworks/community/blogs/ebi/
• MDN > 開発者向けのWeb技術 > Javascript
Mozilla Developer Network Javascript Portal
https://developer.mozilla.org/ja/docs/Web/JavaScript
• JSLint
To check Javascript bad coding practice
• http://www.jslint.com/
www.ktrick.com
This document are offered under the Creative Commons Attribution 2.1 Japan

More Related Content

What's hot

Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced JavascriptAdieu
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScriptDonald Sipe
 
Beginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptBeginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptStoyan Stefanov
 
Javascript Prototype Visualized
Javascript Prototype VisualizedJavascript Prototype Visualized
Javascript Prototype Visualized军 沈
 
LinkedIn TBC JavaScript 100: Intro
LinkedIn TBC JavaScript 100: IntroLinkedIn TBC JavaScript 100: Intro
LinkedIn TBC JavaScript 100: IntroAdam Crabtree
 
Powerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best PracticesPowerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best PracticesDragos Ionita
 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Aaron Gustafson
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testingVikas Thange
 
JavaScript Design Patterns
JavaScript Design PatternsJavaScript Design Patterns
JavaScript Design PatternsDerek Brown
 
Patterns for JVM languages - Geecon 2014
Patterns for JVM languages - Geecon 2014Patterns for JVM languages - Geecon 2014
Patterns for JVM languages - Geecon 2014Jaroslaw Palka
 
Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]Aaron Gustafson
 
Javascript Common Design Patterns
Javascript Common Design PatternsJavascript Common Design Patterns
Javascript Common Design PatternsPham Huy Tung
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesAnkit Rastogi
 
Understanding Object Oriented Javascript - Coffee@DBG June
Understanding Object Oriented Javascript - Coffee@DBG JuneUnderstanding Object Oriented Javascript - Coffee@DBG June
Understanding Object Oriented Javascript - Coffee@DBG JuneDeepu S Nath
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Librariesjeresig
 
Scalable JavaScript Design Patterns
Scalable JavaScript Design PatternsScalable JavaScript Design Patterns
Scalable JavaScript Design PatternsAddy Osmani
 

What's hot (20)

Java Script Best Practices
Java Script Best PracticesJava Script Best Practices
Java Script Best Practices
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
Beginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptBeginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScript
 
Javascript Prototype Visualized
Javascript Prototype VisualizedJavascript Prototype Visualized
Javascript Prototype Visualized
 
LinkedIn TBC JavaScript 100: Intro
LinkedIn TBC JavaScript 100: IntroLinkedIn TBC JavaScript 100: Intro
LinkedIn TBC JavaScript 100: Intro
 
Powerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best PracticesPowerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best Practices
 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testing
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript Design Patterns
JavaScript Design PatternsJavaScript Design Patterns
JavaScript Design Patterns
 
Patterns for JVM languages - Geecon 2014
Patterns for JVM languages - Geecon 2014Patterns for JVM languages - Geecon 2014
Patterns for JVM languages - Geecon 2014
 
Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]
 
Javascript Common Design Patterns
Javascript Common Design PatternsJavascript Common Design Patterns
Javascript Common Design Patterns
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
 
Understanding Object Oriented Javascript - Coffee@DBG June
Understanding Object Oriented Javascript - Coffee@DBG JuneUnderstanding Object Oriented Javascript - Coffee@DBG June
Understanding Object Oriented Javascript - Coffee@DBG June
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Libraries
 
Scalable JavaScript Design Patterns
Scalable JavaScript Design PatternsScalable JavaScript Design Patterns
Scalable JavaScript Design Patterns
 
Javascript tid-bits
Javascript tid-bitsJavascript tid-bits
Javascript tid-bits
 

Similar to [A 3]Javascript oop for xpages developers - public

Similar to [A 3]Javascript oop for xpages developers - public (20)

4front en
4front en4front en
4front en
 
Javascript
JavascriptJavascript
Javascript
 
Object Oriented Programming In JavaScript
Object Oriented Programming In JavaScriptObject Oriented Programming In JavaScript
Object Oriented Programming In JavaScript
 
Journey of a C# developer into Javascript
Journey of a C# developer into JavascriptJourney of a C# developer into Javascript
Journey of a C# developer into Javascript
 
Java script
Java scriptJava script
Java script
 
Let's JavaScript
Let's JavaScriptLet's JavaScript
Let's JavaScript
 
Oojs 1.1
Oojs 1.1Oojs 1.1
Oojs 1.1
 
Learn JS concepts by implementing jQuery
Learn JS concepts by implementing jQueryLearn JS concepts by implementing jQuery
Learn JS concepts by implementing jQuery
 
Javascript Objects Deep Dive
Javascript Objects Deep DiveJavascript Objects Deep Dive
Javascript Objects Deep Dive
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)
 
Javascript Everywhere
Javascript EverywhereJavascript Everywhere
Javascript Everywhere
 
JavsScript OOP
JavsScript OOPJavsScript OOP
JavsScript OOP
 
A JIT Smalltalk VM written in itself
A JIT Smalltalk VM written in itselfA JIT Smalltalk VM written in itself
A JIT Smalltalk VM written in itself
 
JavaScript Essentials
JavaScript EssentialsJavaScript Essentials
JavaScript Essentials
 
JS
JSJS
JS
 
Javascript Object Oriented Programming
Javascript Object Oriented ProgrammingJavascript Object Oriented Programming
Javascript Object Oriented Programming
 
JavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingJavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft Training
 
The JavaScript Programming Primer
The JavaScript  Programming PrimerThe JavaScript  Programming Primer
The JavaScript Programming Primer
 
Javascript Primer
Javascript PrimerJavascript Primer
Javascript Primer
 
"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues
 

More from Kazunori Tatsuki

「dominoワークフローはここまで進化した!v12クラウドネイティブがもたらす新たなアプリ運用」ケートリックウェビナー2021.06.25
「dominoワークフローはここまで進化した!v12クラウドネイティブがもたらす新たなアプリ運用」ケートリックウェビナー2021.06.25「dominoワークフローはここまで進化した!v12クラウドネイティブがもたらす新たなアプリ運用」ケートリックウェビナー2021.06.25
「dominoワークフローはここまで進化した!v12クラウドネイティブがもたらす新たなアプリ運用」ケートリックウェビナー2021.06.25Kazunori Tatsuki
 
Xpagesからさらにその先へ、最新Dominoアプリケーション開発で 企業のノーツアプリはこう生まれ変わる
Xpagesからさらにその先へ、最新Dominoアプリケーション開発で企業のノーツアプリはこう生まれ変わるXpagesからさらにその先へ、最新Dominoアプリケーション開発で企業のノーツアプリはこう生まれ変わる
Xpagesからさらにその先へ、最新Dominoアプリケーション開発で 企業のノーツアプリはこう生まれ変わるKazunori Tatsuki
 
XPagesDay 2016 「xpagesでjava開発するぞ!」
XPagesDay 2016 「xpagesでjava開発するぞ!」 XPagesDay 2016 「xpagesでjava開発するぞ!」
XPagesDay 2016 「xpagesでjava開発するぞ!」 Kazunori Tatsuki
 
20151118パートナーソリューションセミナー2015プレゼンテーション public
20151118パートナーソリューションセミナー2015プレゼンテーション   public20151118パートナーソリューションセミナー2015プレゼンテーション   public
20151118パートナーソリューションセミナー2015プレゼンテーション publicKazunori Tatsuki
 
IBM Connect Japan 2016 「ドミノアプリをカンタンWEB化!業務アプリ作成ツール 「Aveedo」のご紹介」
IBM Connect Japan 2016 「ドミノアプリをカンタンWEB化!業務アプリ作成ツール 「Aveedo」のご紹介」IBM Connect Japan 2016 「ドミノアプリをカンタンWEB化!業務アプリ作成ツール 「Aveedo」のご紹介」
IBM Connect Japan 2016 「ドミノアプリをカンタンWEB化!業務アプリ作成ツール 「Aveedo」のご紹介」Kazunori Tatsuki
 
20150225 テクテクlotus技術者夜会 ibm connect ed2015フィードバック 公開用
20150225 テクテクlotus技術者夜会 ibm connect ed2015フィードバック   公開用20150225 テクテクlotus技術者夜会 ibm connect ed2015フィードバック   公開用
20150225 テクテクlotus技術者夜会 ibm connect ed2015フィードバック 公開用Kazunori Tatsuki
 
[A 3]SSJSでも使える!Javascriptでオブジェクト指向プログラミング入門
[A 3]SSJSでも使える!Javascriptでオブジェクト指向プログラミング入門[A 3]SSJSでも使える!Javascriptでオブジェクト指向プログラミング入門
[A 3]SSJSでも使える!Javascriptでオブジェクト指向プログラミング入門Kazunori Tatsuki
 
【C-3】ジャンボフェリー 予約システムの事例からみるXPagesを使った提案・開発の概要
【C-3】ジャンボフェリー 予約システムの事例からみるXPagesを使った提案・開発の概要【C-3】ジャンボフェリー 予約システムの事例からみるXPagesを使った提案・開発の概要
【C-3】ジャンボフェリー 予約システムの事例からみるXPagesを使った提案・開発の概要Kazunori Tatsuki
 

More from Kazunori Tatsuki (8)

「dominoワークフローはここまで進化した!v12クラウドネイティブがもたらす新たなアプリ運用」ケートリックウェビナー2021.06.25
「dominoワークフローはここまで進化した!v12クラウドネイティブがもたらす新たなアプリ運用」ケートリックウェビナー2021.06.25「dominoワークフローはここまで進化した!v12クラウドネイティブがもたらす新たなアプリ運用」ケートリックウェビナー2021.06.25
「dominoワークフローはここまで進化した!v12クラウドネイティブがもたらす新たなアプリ運用」ケートリックウェビナー2021.06.25
 
Xpagesからさらにその先へ、最新Dominoアプリケーション開発で 企業のノーツアプリはこう生まれ変わる
Xpagesからさらにその先へ、最新Dominoアプリケーション開発で企業のノーツアプリはこう生まれ変わるXpagesからさらにその先へ、最新Dominoアプリケーション開発で企業のノーツアプリはこう生まれ変わる
Xpagesからさらにその先へ、最新Dominoアプリケーション開発で 企業のノーツアプリはこう生まれ変わる
 
XPagesDay 2016 「xpagesでjava開発するぞ!」
XPagesDay 2016 「xpagesでjava開発するぞ!」 XPagesDay 2016 「xpagesでjava開発するぞ!」
XPagesDay 2016 「xpagesでjava開発するぞ!」
 
20151118パートナーソリューションセミナー2015プレゼンテーション public
20151118パートナーソリューションセミナー2015プレゼンテーション   public20151118パートナーソリューションセミナー2015プレゼンテーション   public
20151118パートナーソリューションセミナー2015プレゼンテーション public
 
IBM Connect Japan 2016 「ドミノアプリをカンタンWEB化!業務アプリ作成ツール 「Aveedo」のご紹介」
IBM Connect Japan 2016 「ドミノアプリをカンタンWEB化!業務アプリ作成ツール 「Aveedo」のご紹介」IBM Connect Japan 2016 「ドミノアプリをカンタンWEB化!業務アプリ作成ツール 「Aveedo」のご紹介」
IBM Connect Japan 2016 「ドミノアプリをカンタンWEB化!業務アプリ作成ツール 「Aveedo」のご紹介」
 
20150225 テクテクlotus技術者夜会 ibm connect ed2015フィードバック 公開用
20150225 テクテクlotus技術者夜会 ibm connect ed2015フィードバック   公開用20150225 テクテクlotus技術者夜会 ibm connect ed2015フィードバック   公開用
20150225 テクテクlotus技術者夜会 ibm connect ed2015フィードバック 公開用
 
[A 3]SSJSでも使える!Javascriptでオブジェクト指向プログラミング入門
[A 3]SSJSでも使える!Javascriptでオブジェクト指向プログラミング入門[A 3]SSJSでも使える!Javascriptでオブジェクト指向プログラミング入門
[A 3]SSJSでも使える!Javascriptでオブジェクト指向プログラミング入門
 
【C-3】ジャンボフェリー 予約システムの事例からみるXPagesを使った提案・開発の概要
【C-3】ジャンボフェリー 予約システムの事例からみるXPagesを使った提案・開発の概要【C-3】ジャンボフェリー 予約システムの事例からみるXPagesを使った提案・開発の概要
【C-3】ジャンボフェリー 予約システムの事例からみるXPagesを使った提案・開発の概要
 

Recently uploaded

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 

Recently uploaded (20)

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 

[A 3]Javascript oop for xpages developers - public

  • 1. www.ktrick.com A-3 Javascript OOP for XPages Developers Kazunori Tatsuki @ Ktrick Co,. Ltd.
  • 2. • Name: Kazunori Tatsuki • Company: KTrick Co,. Ltd. • Title: Owner of KTrick Co,. Ltd. • My Experience: - 7 years development experience as IBM Vender in US. - XPages and all other domino related languages, C, C++, Objective-C, Java, PHP etc. Introduction
  • 3. Are you struggling with developing XPages application? Why?
  • 4. Javascript? Client side Javascript… Sever side Javascript… What’s different?
  • 5. Nowadays Javascript sample code is like this … var func1 = function(){ alert("hello!"); } var myButton = new Button({ label: "Show me!", onClick: function(){ myDialog.set("content", “Hello!"); myDialog.show(); } }, "progbutton").startup();
  • 6. Javascript used to be like this… function func1(param){ alert( param); } It is easier to understand, isn’t it? Why has it changed?
  • 7. Have you ever seen this? ( function() { //contents here… }() ); Hmmm, Too much parenthesis… Actually these are all different meaning.
  • 9. In this session, I would like you to understand the structure of Javascript by breaking down the source code one by one.
  • 10. Object Oriented Programming What’s the benefits of using OOP?
  • 11. Benefits of OOP ・Reusability ・ Refactoring ・ Extensibility ・ Maintenance ・ Efficiency As a result, you can reduce the time and cost for development and testing.
  • 12. OOP What do you imagine from this word?
  • 14. If you already have OOP experience, you may think of 「 Class 」
  • 15. Is there class in Javascript?
  • 16. Nope
  • 17. How can we develop OOP without class?
  • 20. To begin with, Javascript only has Object.
  • 21. sub Class (type) By the way, Class is like this… Super Class (type) Object (Instance) Object (Instance) Object (Instance) NEW NEW NEW Class is like ‘type’. You define the class as the abstract type for instance. Then you can generate the instances from the classes. By doing this, you can generate same type objects (instances) easily ,which have the same functions and attributes.
  • 22. Again, Javascript doesn’t have Class structure… then…
  • 23. Javascript Prototype chain is like this… Object (Instance) Object (Instance) Object (Instance) Object (Instance) Dele gate Dele gate Dele gate You can connect the objects and objects like chain. Then if the original object doesn’t have the specific methods or variables, then Javascript delegates to search in the other object until they are found. Object (Instance) Dele gate
  • 24. Let’s take a look at the actual source code. ※Basically please consider that the sample codes are written in client side Javascript because server side Javascript cannot use some methods like alert(). However the theories and structures are the same!
  • 26. How to generate Object? var obj = { }; That’s it. An empty object was generated.
  • 27. Object structure var obj = { key: value }; Object can have Properties (the set of Key and value) That’s it! var obj = { name : “Apple”, size : 500 }; alert(obj.name); (i.e.)
  • 28. var obj = { func1 : function( ) {alert(“hoge”); } }; obj.func1(); // Output is “hoge” In Javascript, even the method is a “value” var func = function( ){}; A method is a value, therefore you can set it to a variable. Of course, you can operate variables as usual. (i.e) You can set the method to object property.
  • 29. Finally, explanation of Prototype Chain !! It’s THE Javascript OOP
  • 30. There are two important keywords below when learning Javascript Prototype Chain. ➲ __proto__ ➲prototype It’s very important to understand what is different from each other to understand Javascript OOP.
  • 32. __proto__ ・[Rule] All objects in Javascript have [[Prototype]] internally. However some browser application like Chrome, Firefox etc allow you to access the [[Prototype]] by using __proto__ property instead. Internal means that you basically cannot access to the [[Prototype]]
  • 33. Like this… Object (Instance) Object (Instance) Object (Instance) Object (Instance) Dele gate Dele gate Dele gate __proto__ __proto__ __proto__ __proto__
  • 34. Sample code (This sample code works in Chrome & Firefox since allowing you to access by using “__proto__” ) However this code alert “It is Apple” var obj = { name : “none”, callMe : function() { alert(“It is ” + this.name); } }; var objApple = { name : “Apple”}; objApple.__proto__ = obj; var objBlackbox = { }; objBlackbox.__proto__ = objApple; objBlackbox.callMe(); Object is empty…
  • 35. Confirm the order of source code(1) It alerts “It is Apple” Generates object named obj. It has name and callMe property. Generates object named objApple. name property is ”Apple”. Generates object named objBlackbox. There is no property. var obj = { name : “none”, callMe : function() { alert(“It is ” + this.name); } }; var objApple = { name : “Apple”}; objApple.__proto__ = obj; var objBlackbox = { }; objBlackbox.__proto__ = objApple; objBlackbox.callMe();
  • 36. Confirm the order of source code (2) Set “obj” into objApple.__proto_ var obj = { name : “none”, callMe : function() { alert(“It is ” + this.name); } }; var objApple = { name : “Apple”}; objApple.__proto__ = obj; var objBlackbox = { }; objBlackbox.__proto__ = objApple; objBlackbox.callMe(); Generate object named obj. It has name and callMe property. Generate object named objApple. name property is ”Apple”. Generate object named objBlackbox. There is no property.
  • 37. Set “objApple” int objBlackbox.__proto__ var obj = { name : “none”, callMe : function() { alert(“It is ” + this.name); } }; var objApple = { name : “Apple”}; objApple.__proto__ = obj; var objBlackbox = { }; objBlackbox.__proto__ = objApple; objBlackbox.callMe(); Set “obj” into objApple.__proto_ Generate object named obj. It has name and callMe property. Generate object named objApple. name property is ”Apple”. Generate object named objBlackbox. There is no property. Confirm the order of source code (3)
  • 38. Confirm the method call (1) var obj = { name : “none”, callMe : function() { alert(“It is ” + this.name); } }; var objApple = { name : “Apple”}; objApple.__proto__ = obj; var objBlackbox = { }; objBlackbox.__proto__ = objApple; objBlackbox.callMe();
  • 39. (1) There is no callMe() method in objBlackbox var obj = { name : “none”, callMe : function() { alert(“It is ” + this.name); } }; var objApple = { name : “Apple”}; objApple.__proto__ = obj; var objBlackbox = { }; objBlackbox.__proto__ = objApple; objBlackbox.callMe(); Confirm the method call (2)
  • 40. (2)Search object stored in __proto__ (objApple) var obj = { name : “none”, callMe : function() { alert(“It is ” + this.name); } }; var objApple = { name : “Apple”}; objApple.__proto__ = obj; var objBlackbox = { }; objBlackbox.__proto__ = objApple; objBlackbox.callMe(); Confirm the method call (3) (1) There is no callMe() method in objBlackbox
  • 41. (3) There is no callMe() method in objApple neither. var obj = { name : “none”, callMe : function() { alert(“It is ” + this.name); } }; var objApple = { name : “Apple”}; objApple.__proto__ = obj; var objBlackbox = { }; objBlackbox.__proto__ = objApple; objBlackbox.callMe(); (2)Search object stored in __proto__ (objApple) (1) There is no callMe() method in objBlackbox Confirm the method call (4)
  • 42. (4) Serach object stored in __proto__ (obj) var obj = { name : “none”, callMe : function() { alert(“It is ” + this.name); } }; var objApple = { name : “Apple”}; objApple.__proto__ = obj; var objBlackbox = { }; objBlackbox.__proto__ = objApple; objBlackbox.callMe(); Confirm the method call (5) (3) There is no callMe() method in objApple neither. (2)Search object stored in __proto__ (objApple) (1) There is no callMe() method in objBlackbox
  • 43. (5) Found callMe() method in obj!var obj = { name : “none”, callMe : function() { alert(“It is ” + this.name); } }; var objApple = { name : “Apple”}; objApple.__proto__ = obj; var objBlackbox = { }; objBlackbox.__proto__ = objApple; objBlackbox.callMe(); (4) Serach object stored in __proto__ (obj) Confirm the method call (6) (3) There is no callMe() method in objApple neither. (2)Search object stored in __proto__ (objApple) (1) There is no callMe() method in objBlackbox
  • 44. (1) callMe() method is called. var obj = { name : “none”, callMe : function() { alert(“It is ” + this.name); } }; var objApple = { name : “Apple”}; objApple.__proto__ = obj; var objBlackbox = { }; objBlackbox.__proto__ = objApple; objBlackbox.callMe(); Confirm the attribute call (1)
  • 45. (2) Refer “name” property ※”this” means “object itself.” var obj = { name : “none”, callMe : function() { alert(“It is ” + this.name); } }; var objApple = { name : “Apple”}; objApple.__proto__ = obj; var objBlackbox = { }; objBlackbox.__proto__ = objApple; objBlackbox.callMe(); Confirm the attribute call (2) (1) callMe() method is called.
  • 46. (3) There is no “name” property in objBlackbox var obj = { name : “none”, callMe : function() { alert(“It is ” + this.name); } }; var objApple = { name : “Apple”}; objApple.__proto__ = obj; var objBlackbox = { }; objBlackbox.__proto__ = objApple; objBlackbox.callMe(); (2) Refer “name” property ※”this” means “object itself.” Confirm the attribute call (3) (1) callMe() method is called.
  • 47. (4) Search the object stored in __proto__ (objApple) var obj = { name : “none”, callMe : function() { alert(“It is ” + this.name); } }; var objApple = { name : “Apple”}; objApple.__proto__ = obj; var objBlackbox = { }; objBlackbox.__proto__ = objApple; objBlackbox.callMe(); (3) There is no “name” property in objBlackbox (2) Refer “name” property ※”this” means “object itself.” Confirm the attribute call (4) (1) callMe() method is called.
  • 48. (5) Found ”name“ in objApple ! var obj = { name : “none”, callMe : function() { alert(“It is ” + this.name); } }; var objApple = { name : “Apple”}; objApple.__proto__ = obj; var objBlackbox = { }; objBlackbox.__proto__ = objApple; objBlackbox.callMe(); (4) Search the object stored in __proto__ (objApple) (3) There is no “name” property in objBlackbox (2) Refer “name” property ※”this” means “object itself.” Confirm the attribute call (5) (1) callMe() method is called.
  • 49. (6) There is “name” property in obj as well. However not referred var obj = { name : “none”, callMe : function() { alert(“It is ” + this.name); } }; var objApple = { name : “Apple”}; objApple.__proto__ = obj; var objBlackbox = { }; objBlackbox.__proto__ = objApple; objBlackbox.callMe(); (5) Found ”name“ in objApple ! (4) Search the object stored in __proto__ (objApple) (3) There is no “name” property in objBlackbox (2) Refer “name” property ※”this” means “object itself.” Confirm the attribute call (6) (1) callMe() method is called.
  • 50. Like in the sample code, if the original object does not have the methods or attributes, then Javascript delegates to the chained object to search them via __proto__ until found This is Prototype Chain ! Object (Instance) Object (Instance) Object (Instance) Object (Instance) Dele gate Dele gate Dele gate Not Found Found Not Found Not Found
  • 51. Now is it ok to understand __proto__ ?
  • 52. Wait a minutes… __proto__ (aka [[Prototype]]) is just internal property. Then we should not use the code like below... objApple.__proto__ = obj; Is it true?
  • 53. Yes, Do not use it!
  • 54. In fact I used the code like below as an example so that I can explain the internal mechanism more clearly. However, there is an alternative way to achieve the same logic. var objApple = { name : “Apple”}; objApple.__proto__ = obj;
  • 55. The answer is using “New” operation (i.e.)This is the sample code equivalent to the previous sample. var obj = new Frout(“Apple”); Breakdown of this code later on. var Frout = function( pname ) { this.name = pname; } Frout.prototype.callMe = function() { alert(“It is ” + this.name); }; var objApple = new Frout(“Apple”);
  • 56. ➲ prototype Before moving forward, there is an another keyword called ”prototype” It’s very important to understand what is different from __proto__!
  • 57. prototype ・[Rule] All function objects have prototype property. “function object” Hmm, New keyword again... But don’t worry. You already know this.
  • 58. Function Object is like this… It was already explained in previous slide. Function(method) can be value. var func = function( ){};
  • 59. All Function Objects have prototype property. Again, For example, var func = function( ){}; alert( func.prototype ); The second line above does not output “undefined”. This means prototype exists as the default. However after defining the function object, the prototype refer just empty object. Then, How to use prototype?
  • 60. The answer is… Prototype is used with new operation when the object is generated!
  • 61. Confirm by source code (This is the sample code equivalent to previous sample for __proto__) Define Constructor Generates Function Object. name is undefined at this moment. Set the method to the prototype property of Frout object. Generate objApple object by using new operation. By the prototype chain, objApple can call the callMe() method of Frout prototype var Frout = function( pname ) { this.name = pname; } Frout.prototype.callMe = function() { alert(“It is ” + this.name); }; var objApple = new Frout(“Apple”); objApple.callMe(); Alert 「It is Apple」 ※ it is not “objApple.prototype.callMe() “ Explain in the next slide
  • 62. var obj = {}; obj.__proto__ = Frout.prototype; Frout.apply(obj, arguments ); return obj; Try to breakdown the process of new operation artificially. var objApple = new Frout(“Apple”);
  • 63. var obj = {}; obj.__proto__ = Frout.prototype; Frout.apply(obj, arguments ); return obj; (1) Generates object. var objApple = new Frout(“Apple”); Try to breakdown the process of new operation artificially.
  • 64. var obj = {}; obj.__proto__ = Frout.prototype; Frout.apply(obj, arguments ); return obj; (2) Set prototype property into __proto__. Frout.prototype Has callMe() method. Frout.prototype.callMe = function() { alert(“It is ” + this.name); }; var objApple = new Frout(“Apple”); Try to breakdown the process of new operation artificially. (1) Generate object.
  • 65. var obj = {}; obj.__proto__ = Frout.prototype; Frout.apply(obj, arguments ); return obj; (3) Execute constructor function. Constructor function is executed only when function object is generated. Frout.prototype.callMe = function() { alert(“It is ” + this.name); }; var objApple = new Frout(“Apple”); Try to breakdown the process of new operation artificially. (2) Set prototype property into __proto__. Frout.prototype Has callMe() method. (1) Generate object.
  • 66. var obj = {}; obj.__proto__ = Frout.prototype; Frout.apply(obj, arguments ); return obj; (4) Returns the object. Frout.prototype.callMe = function() { alert(“It is ” + this.name); }; var objApple = new Frout(“Apple”); Try to breakdown the process of new operation artificially. (3) Execute constructor function. Constructor function is executed only when function object is generated. (2) Set prototype property into __proto__. Frout.prototype Has callMe() method. (1) Generate object.
  • 67. var obj = {}; obj.__proto__ = Frout.prototype; Frout.apply(obj, arguments ); return obj; Frout.prototype.callMe = function() { alert(“It is ” + this.name); }; var objApple = new Frout(“Apple”); var objApple = new Frout(“Apple”); Try to breakdown the process of new operation artificially. (4) Return the object. (3) Execute constructor function. Constructor function is executed only when function object is generated. (2) Set prototype property into __proto__. Frout.prototype Has callMe() method. (1) Generate object.
  • 68. The sample code using for explanation of __proto__ var obj = {}; obj.__proto__ = Frout.prototype; Frout.apply(obj, arguments ); return obj; The breakdown process of new operation artificially. If you replace obj to Frout.prototype, then both objects have callMe() Frout.prototype.callMe = function() {…}; var obj = { name : “none”, callMe : function() { … } }; var objApple = { name : “Apple”}; objApple.__proto__ = obj;
  • 69. Difference between __proto__ and prototype Prototype is used when object is generated by new operation to be stored in __proto__. Used by prototype search mechanism internally. By the new operation, object prototype is automatically stored. __proto__ prototype To make a prototype chain, use this prototype. __proto__ is just needed to understand the internal mechanism. Use new and prototype for OOP.
  • 70. So, a little Brain Teaser
  • 71. Frout object preparation and if we describe We don’t want to write this, correct? It is not useful var Frout = function( name ) { this.name = name; } Frout.prototype.callMe = function() { alert(“It is ” + this.name); }; var Frout = function( name ) { this.name = name; this.callMe = function() { alert(“It is ” + this.name); }; }
  • 72. From an OOP perspective this is bad But let’s continue…
  • 73. The reason: var Frout = function( name ) { this.name = name; this.callMe = function() { alert(“It is ” + this.name); }; } In this code, without a prototype, it will be defined inside the constructor In other words: Everytime new is called to create this object, callMe is also instantiated. In Contrast, methods defined in the prototype, falls within the prototype chain inconsistently Memory efficiency is better because the mechanism allows reference to the same memory when new objects are created. Frout.prototype.callMe = function() { alert(“It is ” + this.name); };
  • 75. From the sample code earlier: This function of brackets is integral to what kind of work? ( function() { //code }() );
  • 76. Arriving at the conclusion Calling an anonymous function immediately We are going to do this
  • 77. Immediately after the function object is returned, we're calling the function. Create function Object。 ( function() { //code・・・ }() ); Anonymous funtion with no variable This was done through a very complicated process。 This is used as such that when the page is loaded, it processes only once。 There are 2 parts? //Immediate function1 (function () { //code・・・ }()); //Immediate function2 (function () { //code・・・ })(); Both are immediate function. In JSLint(http://www.jslint.com/) the former code seems to be preferred
  • 79. the result… var Frout = function( name ) { this.name = name; } Frout.prototype.callMe = function() { alert(“It is ” + this.name); }; var objApple = new Frout(“Apple”); alert( objApple.name ); You should not be able see if it was private variable Is this a private variable? protected variable? public variable? To be considered OOP, don’t we want to hide the private variable?
  • 80. (Naturally)we are able to see orz but wait a minute…
  • 81. I modified something like this var FroutModel = (function() { // private variable var name = “none"; // Constructor var cls = function(pname){name = pname;}; // public method cls.prototype.callMe = function() {alert("This is "+name);}; return cls; } () ); var Frout = function( name ) { this.name = name; } Frout.prototype.callMe = function() { alert(“It is ” + this.name); }; Before re edit
  • 82. var FroutModel = (function() { // private variable var name = “none"; // Constructor var cls = function(pname){name = pname;}; // public method cls.prototype.callMe = function() {alert("This is "+name);}; return cls; } () ); var objApple = new FroutModel(“Apple”); alert( objApple.name ); objApple.callMe(); To make sure that undefined is hidden Can be successfully called
  • 83. Somehow it very much looks like a class
  • 84. In addition to class inheritance, you can implement like this: var FroutModel = (function() { // private variable var name = “none"; // Constructor var cls = function(pname){name = pname;}; // Parent class inheritance cls.prototype = new BaseModel(); // public method cls.prototype.callMe = function() {alert("This is "+name);}; return cls; } () ); Like this: BaseModel object and FroutModel object are doing the same implementation
  • 85. Below are some descriptions about the code up to now. Please challenge yourself by solving the puzzle var FroutModel = (function() { // private variable var name = “none"; // constructor var cls = function(pname){name = pname;}; // parent class inheritance cls.prototype = new BaseModel(); // public method cls.prototype.callMe = function() {alert("This is "+name);}; return cls; } () ); Hint: Scope chain cannot be seen from the outside Hint:Generate another object inside the FroutModel function Hint: Returns the object that was generated in the FroutModel Hint: Immediate function
  • 86. This time、 XPages discussion has not even come out yet…
  • 87. Now, Javascript has two types: Client-side Javascript Server-side Javascript Both have the concept of class
  • 88. Lets try the last class’s implementation of SSJS. It’s also useful to copy to script lib var AppModel = (function() { // private variable var name = “none"; // constructor var cls = function(pname){name = pname;}; // parent class inheritance cls.prototype = new BaseModel(); // public method cls.prototype.func1 = function() {…}; return cls; } () ); Actually、the Javascript structure has their own OOP template, which I don’t like.
  • 89. Cut paste to script library
  • 90. Xpages call から呼び出し Output Result Storing the new object using viewScope
  • 91. Some notes when using OOP in XPages Previously, we have stored the new object into viewScope. In order to use objects persistently, choose “Save the page in memory” at the XSP property setting
  • 92. What do you think so far? In order to better understand Object-oriented in Javascript, I think it is best to try various concept I prepared an HTML file for you to test  <!DOCTYPE html> <html> <head> <script type="text/javascript"> // <![CDATA[ var FroutModel = (function() { // private variable var name = "hoge"; // コンストラクタ var cls = function(pname){name = pname;}; // メソッド cls.prototype.callMe = function() {alert("This is "+name);}; return cls; }()); var frt = new FroutModel("Banana"); frt.callMe(); alert("frout.name="+frt.name); // ]]> </script> </head> <body> </body> </html>
  • 93. Note that we are no longer afraid of Dojo and jQuery
  • 94. R e f e r e n c e s • 最強オブジェクト指向言語 JavaScript 再入門 Yuji Nojima slides. Developer at Foreignkey, Co. Ltd. http://www.slideshare.net/yuka2py/javascript-23768378 • ブログ XPagesで行こう! Kenji Ebihara’s blog. IBM Champion. Ricoh IT Solution https://www.ibm.com/developerworks/community/blogs/ebi/ • MDN > 開発者向けのWeb技術 > Javascript Mozilla Developer Network Javascript Portal https://developer.mozilla.org/ja/docs/Web/JavaScript • JSLint To check Javascript bad coding practice • http://www.jslint.com/
  • 95.
  • 96. www.ktrick.com This document are offered under the Creative Commons Attribution 2.1 Japan