JS 对象API之获取原型对象

本文介绍了JavaScript中通过构造函数获取原型对象的方法,包括直接从构造函数访问原型及通过对象实例的不同方式追溯其原型。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、从 构造函数 获得 原型对象:

构造函数.prototype

2、 对象实例 获得 父级原型对象

方法一: 对象实例.__proto__        【 有兼容性问题,不建议使用】

方法二:Object.getPrototypeOf( 对象实例 )

 

代码栗子:

function Student(){
    this.name = "小马扎"; 
    this.age = 18;
}
var lilei = new Student();  // 创建对象实例
console.log(Student.prototype);  //Student{}
console.log(lilei.__proto__);  //Student{}
console.log(Object.getPrototypeOf(lilei));    //Student{}

 

转载于:https://www.cnblogs.com/minigrasshopper/p/8066735.html

fortune 是一个超媒体 API 原型框架,实现 JSON API 规范。fortune 具有一个模块化的持久层,里面包括了 NeDB (内联), MongoDB, MySQL, Postgres 和 SQLite 的适配器,可以查看 引导手册 了解如何使用。Fortune 实现了所有 JSON API 的规范,还有一些其他的特性:使用简单, Fortune 提供免费的路线控制和数据库交互,不需要用户制作管道。关联和双向关系的映射,不需要用户管理资源之间的关联关系。在编辑前或者阅览之后,自动变换资源,实现特定的应用逻辑fortune 没有相关的授权和身份验证,你可以在你的应用中实现,可以查看样板:keystore.js 。用 npm 安装:  $ npm install fortune示例代码:import fortune from 'fortune' import http from 'http' const store = fortune.create() // The `net.http` function returns a listener function which does content // negotiation, parses headers, and maps the response to an HTTP response. const server = http.createServer(fortune.net.http(store)) store.defineType('user', {   name: { type: String },   // Following and followers are inversely related (many-to-many).   following: { link: 'user', inverse: 'followers', isArray: true },   followers: { link: 'user', inverse: 'following', isArray: true },   // Many-to-one relationship of user posts to post author.   posts: { link: 'post', inverse: 'author', isArray: true } }) store.defineType('post', {   message: { type: String },   // One-to-many relationship of post author to user posts.   author: { link: 'user', inverse: 'posts' } }) store.connect().then(() => server.listen(1337)) 标签:Fortune
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值