Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
创建对象的Javascript扩展函数_Javascript_Oop - Fatal编程技术网

创建对象的Javascript扩展函数

创建对象的Javascript扩展函数,javascript,oop,Javascript,Oop,经过一些研究,我还没有找到任何关于在js中扩展函数的“教程”。这不像 var old=some_func; some_func=function(){old();do_some_stuff();}; 但是就像(我要用java展示这个): 类点{ 受保护整数x=0; 受保护整数y=1; } 类MagicPoint扩展点{ 受保护的int颜色=2; } 在这个代码类中是我的函数。我想得到像这样的东西 函数Object1(){ 这个。a=0; } 函数Object2(){ 这是b=1; } var

经过一些研究,我还没有找到任何关于在js中扩展函数的“教程”。这不像

var old=some_func;
some_func=function(){old();do_some_stuff();};
但是就像(我要用java展示这个):

类点{
受保护整数x=0;
受保护整数y=1;
}
类MagicPoint扩展点{
受保护的int颜色=2;
}
在这个代码类中是我的函数。我想得到像这样的东西

函数Object1(){
这个。a=0;
}
函数Object2(){
这是b=1;
}
var Object3=extend(Object1,Object2);
var abc=newobject3();
abc:
a=0

b=1

下面的内容应该适合您

Function.prototype.inherits = function(parent) {
 this.prototype = Object.create(parent.prototype);
};

function Object1(){
  this.a = 0;
}

function Object2(){
  this.b = 1;
}

Object3.inherits(Object1);
Object3.inherits(Object2);

function Object3() {
  Object1.apply(this, arguments);Object2.apply(this,arguments);
}

var e = new Object3();

console.log(e.a);
console.log(e.b);

下面应该适合你

Function.prototype.inherits = function(parent) {
 this.prototype = Object.create(parent.prototype);
};

function Object1(){
  this.a = 0;
}

function Object2(){
  this.b = 1;
}

Object3.inherits(Object1);
Object3.inherits(Object2);

function Object3() {
  Object1.apply(this, arguments);Object2.apply(this,arguments);
}

var e = new Object3();

console.log(e.a);
console.log(e.b);

下面应该适合你

Function.prototype.inherits = function(parent) {
 this.prototype = Object.create(parent.prototype);
};

function Object1(){
  this.a = 0;
}

function Object2(){
  this.b = 1;
}

Object3.inherits(Object1);
Object3.inherits(Object2);

function Object3() {
  Object1.apply(this, arguments);Object2.apply(this,arguments);
}

var e = new Object3();

console.log(e.a);
console.log(e.b);

下面应该适合你

Function.prototype.inherits = function(parent) {
 this.prototype = Object.create(parent.prototype);
};

function Object1(){
  this.a = 0;
}

function Object2(){
  this.b = 1;
}

Object3.inherits(Object1);
Object3.inherits(Object2);

function Object3() {
  Object1.apply(this, arguments);Object2.apply(this,arguments);
}

var e = new Object3();

console.log(e.a);
console.log(e.b);

帮助很大。您能解释一下Object1.apply的作用吗?简单来说,Object1.apply(这个,参数)允许当前对象(这个)即Object3访问函数Object1作用域。想了解更多信息,我帮了大忙。您能解释一下Object1.apply的作用吗?简单来说,Object1.apply(这个,参数)允许当前对象(这个)即Object3访问函数Object1作用域。想了解更多信息,我帮了大忙。您能解释一下Object1.apply的作用吗?简单来说,Object1.apply(这个,参数)允许当前对象(这个)即Object3访问函数Object1作用域。想了解更多信息,我帮了大忙。您能解释一下Object1.apply的作用吗?简单来说,Object1.apply(这个,参数)允许当前对象(这个)即Object3访问函数Object1作用域。更多信息