<script language="javascript">
/*
var myobj={};
myobj.name = "my precious";
myobj.getName = function(){
return this.name;
}
alert(myobj.getName());
var another={
name: "my other precious";
getName: function(){
return this.name;
}
}
function a(){};a();
和
(function a(){})();
是一个意思,后者是内联写法。
if ( window.jQuery )
var _jQuery = window.jQuery;
这句是为了防止jQuery变量名被占用而给别人代码造成破坏,故换个名字_jQuery。
以下是我学习的以及在网上的一点积累,哈哈!
*/
(function(){
var rgz=window.rgz = window.$1 ={
getBase: function(){
return new Base();
},
a:"aaaa"
}
function Base(){
}
Base.prototype={
rName : "rengz",
rHeight: "177",
toString : function(){
return this.rName+" "+this.rHeight;
},
getShiny : function(){
return shiny;
}
}
var shiny = {
shiny: true,
round: true
}
var normal = {
name: 'parent1',
getName: function() {
return this.name;
}
}
var normal1 = {
name1: 'parent2',
getName1: function() {
return this.name1;
}
}
function A(){
this.aName="a";
this.aId ="12";
this.getAName=function(){
return this.aName;
}
}
function extend(parent, child){
for(var i in parent){
child[i] = parent[i];
}
}
extend(normal,shiny);
extend(normal1,shiny);
})();
(function (){
var azhu= window.azhu = window.$=function(){
return {a:"aaaa",b:"bbbbb"};
};
})();
alert(azhu().a);
alert(rgz.getBase());
</script>
内联与继承
/*
var myobj={};
myobj.name = "my precious";
myobj.getName = function(){
return this.name;
}
alert(myobj.getName());
var another={
name: "my other precious";
getName: function(){
return this.name;
}
}
function a(){};a();
和
(function a(){})();
是一个意思,后者是内联写法。
if ( window.jQuery )
var _jQuery = window.jQuery;
这句是为了防止jQuery变量名被占用而给别人代码造成破坏,故换个名字_jQuery。
以下是我学习的以及在网上的一点积累,哈哈!
*/
(function(){
var rgz=window.rgz = window.$1 ={
getBase: function(){
return new Base();
},
a:"aaaa"
}
function Base(){
}
Base.prototype={
rName : "rengz",
rHeight: "177",
toString : function(){
return this.rName+" "+this.rHeight;
},
getShiny : function(){
return shiny;
}
}
var shiny = {
shiny: true,
round: true
}
var normal = {
name: 'parent1',
getName: function() {
return this.name;
}
}
var normal1 = {
name1: 'parent2',
getName1: function() {
return this.name1;
}
}
function A(){
this.aName="a";
this.aId ="12";
this.getAName=function(){
return this.aName;
}
}
function extend(parent, child){
for(var i in parent){
child[i] = parent[i];
}
}
extend(normal,shiny);
extend(normal1,shiny);
})();
(function (){
var azhu= window.azhu = window.$=function(){
return {a:"aaaa",b:"bbbbb"};
};
})();
alert(azhu().a);
alert(rgz.getBase());
</script>
内联与继承