clone.html revision 1b298c6f0ef597aa4ab0b8bcb25430b6c9a87749
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>YUI 3.0</title>
<!--
<script type="text/javascript" src="http://yui.yahooapis.com/3.0.0pr2/build/yui/yui-min.js"></script>
-->
<script type="text/javascript" src="/build3x/yui/yui-debug.js"></script>
<script type="text/javascript">
YUI({
base: '/build3x/',
filter: 'debug'
}).use('oop', 'dump', function(Y) {
var o = {
str: "object1",
arr: [
"array1",
true,
{ obj: "obj"},
["array2"]
],
dat: new Date(),
fn: function() {
Y.log('fn ' + this.str);
},
obj: {
a: [1]
},
regex: /foo/,
nada: null
}
// var o2 = Y.clone(o, true);
var o2 = Y.clone(o);
o2.str = 'object2';
Y.log(Y.dump(o));
Y.log(Y.dump(o2));
Y.log(o2.regex instanceof RegExp);
Y.log(!!Y.Lang.isValue(o2.nothing));
});
/*
YUI().use('oop', 'dump', function(Y) {
var o = {
name: 'object',
id: 'object1'
};
var o2 = Y.clone(o);
o2.id = 'object2';
Y.log(Y.dump(o));
Y.log(Y.dump(o2));
});
*/
/*
Y = YUI({
base: '/build3x/'
}).use('dump', 'attribute', function(Y) {
var newobj = {},
o = {
str: "str",
arr: [
"array1",
true,
{ obj: "obj"},
["array2"]
],
dat: new Date(),
fn: function() {
Y.log('fn ' + this.str);
},
obj: {
a: [1]
},
regex: /foo/,
//win: window,
nada: null,
// els: document.getElementsByTagName('head'),
state: new Y.State()
};
var o2 = Y.clone(o);
Y.log("orig: " + Y.Lang.dump(o));
Y.log("copy: " + Y.Lang.dump(o2));
o.str = 'changed';
o.date = new Date(0);
// o.obj.a = ['changed'];
// o.obj = { changed: 'changed' };
// o2.obj = { changed: 'copy' };
o.obj.a[0] = 'changed'
Y.log("orig: " + Y.Lang.dump(o));
Y.log("copy: " + Y.Lang.dump(o2));
o.fn();
o2.fn();
// cloned regex literals do not work
// Y.log("fixed regex: " + "i have foo".match(o2.regex));
o.foo = "NewPropShouldNotBeInO2";
Y.log(o2.foo);
function A() {
}
A.prototype = {
str:"bar",
obj: {}
}
var a = new A();
var b = Y.clone(a);
A.prototype.str = "StrShouldNotBeUpdatedInB";
Y.log(b.str);
var seed = { foo : { bar : 'bar' } };
var clone = Y.clone(seed);
Y.log(1,'seed.foo.bar: ' + seed.foo.bar); // 'bar'
Y.log(1,'clone.foo.bar: ' + clone.foo.bar); // 'bar'
seed.foo.bar = 'foo';
Y.log(2,'seed.foo.bar: ' + seed.foo.bar); // 'foo'
Y.log(2,'clone.foo.bar: ' + clone.foo.bar); // 'bar'
delete clone.foo.bar;
Y.log(3,'seed.foo.bar: ' + seed.foo.bar); // 'foo'
Y.log(3,'clone.foo.bar: ' + clone.foo.bar); // 'foo'!
Y.log([].constructor.prototype);
// Y.log(o2.els[0].parentNode);
Y.log(/adam/ instanceof RegExp);
Y.log(o2.state.get('bar'));
// Y.log("-" + Y.Lang.dump(a.constructor.prototype));
});
*/
</script>
<body>
<input id="addButton" type="button" value="Add link" />
</body>
</html>