clone.html revision 1b298c6f0ef597aa4ab0b8bcb25430b6c9a87749
<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">
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() {
},
obj: {
a: [1]
},
regex: /foo/,
nada: null
}
// var o2 = Y.clone(o, true);
var o2 = Y.clone(o);
o2.str = 'object2';
});
/*
YUI().use('oop', 'dump', function(Y) {
var o = {
name: 'object',
id: 'object1'
};
var o2 = Y.clone(o);
o2.id = 'object2';
});
*/
/*
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() {
},
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
o.foo = "NewPropShouldNotBeInO2";
function A() {
}
A.prototype = {
str:"bar",
obj: {}
}
var a = new A();
var b = Y.clone(a);
A.prototype.str = "StrShouldNotBeUpdatedInB";
var seed = { foo : { bar : 'bar' } };
var clone = Y.clone(seed);
seed.foo.bar = 'foo';
delete clone.foo.bar;
Y.log(/adam/ instanceof RegExp);
Y.log(o2.state.get('bar'));
});
*/
</script>
<body>
<input id="addButton" type="button" value="Add link" />
</body>
</html>