-
Notifications
You must be signed in to change notification settings - Fork 0
/
lazyObject.html
61 lines (48 loc) · 1.58 KB
/
lazyObject.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>
<script src="simpleDeferred.js"></script>
<script src="lazyObject.js"></script>
<script type="text/javascript">
$(function() {
var l = lazyObject();
l.set({
'sleepy': 'wheee1',
'lazy': 'laaaaaazy'
});
l.with('sleepy', function(sleepy) {
console.log(sleepy);
}, window);
l.with('lazy', function(lazy) {
console.log(lazy);
});
setTimeout(function() {
l.set({'sleepy': 'sleepy'});
l.with(['lazy', 'sleepy'],function(lazy, sleepy) {
console.log(lazy, sleepy);
});
}, 1000);
var d1 = deferred();
var d2 = deferred();
var d3 = deferred();
d1.resolve('failure');
when(d1, d2, d3).done(function(v1, v2, v3) {
console.log(v1, v2, v3);
});
d1.resolve('success2');
d2.resolve('success3');
setTimeout(function() {
d2.resolve('failure');
d3.resolve('success4');
}, 3000);
when(d1, d2, d3).done(function(v1, v2, v3) {
console.log(v1, v2, v3);
});
l.with('lazy', 'aaaa');
});
</script>
</head>
<body>
</body>
</html>