简体   繁体   English

如何在Javascript中创建一个继承另一个函数的属性和方法的函数?

[英]How can I create a function in Javascript that inherits properties and methods of another function?

Say I have a function: 说我有一个功能:

function parent() {
   var address = "house";
   var getAddress = function () {
       return address;
   }
}

How can I make another function that inherits these things? 我该如何做另一个继承这些东西的功能?

how about below : 下面如何:

function otherFunc()
{
    addr = parent();
    //other stuff..
}

slight modification in your function to make it as per above usage: 对功能进行细微修改以使其符合上述用法:

function parent() {
   var address = "house";
   var getAddress = function () {
       return address;
   }
return address;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在另一个JavaScript函数中调用一个JavaScript函数? - How can I call one JavaScript function in another JavaScript function? 每次在 JavaScript 中调用 function 时,如何创建具有用户定义属性的新对象? - How can I create new objects with user defined properties every time a function is called in JavaScript? 如何在另一个框架中创建函数? - How can I create a function in another frame? JavaScript:创建使用具有特定属性的方法返回对象的工厂函数 - JavaScript: Create Factory Function that Returns Object with Methods That Have Specific Properties 如何在Javascript中创建异步函数? - How can I create an Asynchronous function in Javascript? 如何访问同一组件中另一个 function 的属性? - How can I access properties of another function in same component? 如何将 function 传递到 JavaScript 中的另一个 function - how can I pass a function into another function in JavaScript 如何在另一个函数的回调中调用JavaScript函数? - How can I call a JavaScript function in a callback of another function? 如何在另一个函数中调用javascript函数? - how can i call a javascript function in another function? 如何在 javascript 的另一个 function 中使用 function 的变量? - how can i use a variable of a function in another function in javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM