Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Essential YUI
1. Essential YUI
{ An introduction to Yahoo!’s JavaScript library
Derrick McMillen, March 2012
2. Why do we need libraries?
• The DOM is difficult to use, verbose,
and inconsistent (see DOM levels).
• We must always respect the global
namespace !
• Building advanced web applications
requires abstraction.
• Leveraging other developer’s code
makes our lives easier.
3. The Yahoo! User Interface
library is a tool to help you
avoid these pitfalls!
4. The YUI Seed
<html>
<body>
<!-- your page content -->
<!-- YUI seed-->
<script src=‚…"></script>
<script src=‚…">
// your JavaScript
</script>
</body>
</html>
5. Quiz
// finds the greatest common divisor
function gcd(a, b) {
if(b === 0)
return a;
else {
x = a % b;
return gcd(b, x);
}
}
x = 5;
y = gcd(12, 4) + x; // what is y?
7. DOM nodes
var d = document;
var body = d.getElementsByTagName(‘body’)[0],
p = d.createElement(‘p’),
txt = d.createTextNode(‘Hello world!’);
body.appendChild(p.appendChild(txt));
14. var Animal = function(n) {
var noise = n;
this.makeNoise = function() {
alert(noise);
}
};
var Dog = function () {
this.bark = function() {
this.makeNoise();
}
};
Dog.prototype = new Animal(‘woof!’);
15. var Mammal = function() {
this.baby = function() {
return new Mammal();
}
};
Mammal.prototype = new Animal(); // uh oh…
Dog.prototype = new Mammal(‘woof!’);
fido = new Dog();
fido.bark(); // undefined
fido instanceof Dog //true
fido instanceof Mammal // true
fido instanceof Animal //true
16. The Prototype Chain
Animal
What happened when fido.bark() ?
noise
makeNoise
__proto__ We were unable to { }
provide the
instance of Animal the correct
Mammal argument when instanciated.
baby
__proto__ The noise private field was
never set.
Dog (fido)
bark
__proto__