函数中的this与 this.prototype
2024-09-05 17:22:14
函数中的this添加函数是加在对象上,而this.prototype是添加在原型上,通过prototype的指向来一级一级查找
prototype是构造函数访问原型对象,__proto__是对象实例访问原型对象
Function.prototype.add=function(name,fn){
this.prototype[name]=fn;
return this;
}
var Methods=function(){
this.addObj = function () { console.log("my is add to obj") }
};
Methods.add('a', function () { console.log("a") }).add('b', function () { console.log("b")})
console.log(Methods)
console.log(Methods.prototype)
var che=new Methods();
che.addObj()//"my is add to obj"
che.a()//b
console.log(che.constructor)
console.log(che.constructor == Methods)//true
che.constructor指向构造函数
最新文章
- Android DownloadProvider学习
- javascript opacity兼容性随笔
- 初识你---------Swift【下篇】
- C#基础-ref、out
- 在C#中利用Nuget包使用SQLite数据库和Linq to SQLite
- 关于Java中return和finally谁先执行.
- GWT环境搭建--eclipse
- Oracle core03_ACID
- MYSQL死锁
- Gradle 1.12 翻译——第十四章. 教程 - 杂七杂八
- webUI自动化测试框架---”pyswat“介绍
- python特征提取——pyAudioAnalysis工具包
- https 与 http
- springMVC源码分析--@ModelAttribute使用及运行原理
- css 四周边框角加粗效果
- Python基础:二、python介绍
- Python将是人工智能时代的最佳编程语言
- python之auto鼠标/键盘事件
- Python3.6.2在线安装pymysql模块
- 项目总结02:百度地图js 基本用法介绍
热门文章
- 《Python编程从0到1》笔记4——你分得清“索引和切片”吗?
- Mysql 表空间和 数据页空洞
- Python 入门之 内置模块 -- hashlib模块
- vue-router的query和params的区别
- 微信小程序与内嵌webview之间来回跳转的几点总结,以及二维码的使用
- asp.net运行原理及机制
- LOCATE()和FIND_IN_SET()
- 094、Swarm 中最重要的概念(Swarm01)
- vue elementui table组件内容换行
- python 中if __name__ = '__main__' 的作用