SoFunction
Updated on 2025-04-10

prototype study notes

var Class = {
create: function() {
return function() {
(this, arguments);
}
}
}
Define a class function as a template or prototype for creating the class
How to use
Copy the codeThe code is as follows:

<html>
<title>Test ()</title>
<head>
<script language="JavaScript" type="text/javascript" src=""></script>
<script>
var llinzzi= ();
= {
initialize:function(){
('This is create when initialize');
},
fuv:function(){('This is inline method');}
}
var linChild = new llinzzi();
</script>
</head>
<body>
<script>
//(linChild);
(());
</script>;
</body>
</html>

////
This is create when initialize This is inline method ;
/////
That is, when the prototype(); method is used to create an object, initialize is executed as a special method when creating an instance and is used to initialize.
inherit
= function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
return destination;
}
This method will copy all the properties and methods of the source object to the destination object.
Prototype's extension to the Object class mainly implements inheritance in JavaScript through a static function (destination, source). From a semantic perspective, the (destination, source) method is somewhat logical because it actually only implements a holographic copy from the source object to the target object. However, you can also think that since the target object has the characteristics that all the source object have, it looks like the target object inherits the source object (and extends it).
// make a (shallow) copy of obj1
var obj1 = {
method : "post",
args : ""
};
var obj2 = ({}, obj1);
Use Example:
Copy the codeThe code is as follows:

<html>
<title>Test </title>
<head>
<script language="JavaScript" type="text/javascript" src=""></script>
<script>
function log(message) {
(" >>>>>: " +message);
}
var obj1= {
method : "post",
args : ""
};
var obj2 = ({}, obj1);
log();
log(obj1 == obj2);
log();
log(obj2 == obj1);
</script>
</head>
<body>
</body>
</html>

// merges in the given options object to the default options object
(options, {
args : "data=454",
onComplete : function() { alert("done!"); }
});
// "post"
// "ata=454"
// function() { alert("done!"); }
Example of use:
Copy the codeThe code is as follows:

<html>
<title>Test </title>
<head>
<script language="JavaScript" type="text/javascript" src=""></script>
<script>
function log(message) {
(" >>>>>: " +message);
}
var options= {
method : "post",
args : ""
};
(options, {
args : "data=454",
onComplete : function() { alert("done!");}
});
// "post"
// "ata=454"
// function() { alert("done!"); }
log();
log();
log();
</script>
</head>
<body>
</body>
</html>