- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 Crockford 的书中,“方法”被添加到 Function.prototype
在我的浏览器控制台中,我这样做了
函数.方法
--> 未定义Function.prototype.method=function(name,func){this.prototype[name]=func;返回这个;}
--> 函数(名称,func){this.prototype[ame]=func;返回这个;}
(function(){}).method
--> 函数(名称,func){this.prototype[名称]=func;返回这个;}
函数.方法
--> 函数(名称,func){this.prototype[名称]=func;返回这个;}
我可以理解第 3 步,其中函数文字定义了“方法”
但是为什么在步骤 4 中,在步骤 1 中未定义的 Function.method 突然定义了“method”。
函数是它自身的实例吗?
最佳答案
关于javascript - Douglas Crockford 书中 Function.prototype 上的“方法”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33199807/
只有 3 行代码,但我无法完全理解这一点: Object.create = function (o) { function F() {} F.prototype = o; re
我知道有很多关于“Javascript:好的部分”的问题和文档,但我试图理解书中一句话的意思,但不太明白。在第 41-42 页中,他定义了 serial_maker 函数: var serial_ma
这是什么意思: "When a function object is created, the Function constructor that produces the function obje
下面的代码几乎与道格拉斯·克罗克福德 (Douglas Crockford) 的精湛著作《JavaScript:好的部分》第 29-30 页中的一些代码相同。唯一的区别是他像这样添加了 get_sta
出于兴趣,我想学习如何为一种简单的语言编写解析器,并最终为我自己的代码打高尔夫球语言编写解释器,一旦我了解了这些东西的一般工作原理。 所以我开始阅读 Douglas Crockfords 的文章 To
最近我看了一个 Douglas Crockford 的演讲(他的演讲让我着迷,但总是让我感到困惑)。他举了一个构造函数的例子,但我不太明白我将如何在实践中使用它: function construct
我正在尝试使用 Crockford 的继承模式构建基类 Shape。使用这个基本形状,我试图画一个圆、一个矩形和一个三 Angular 形。我有点卡住了。我不知道如何调用/修改基本方法 functio
我刚读完 The Good Parts,我对某事有点困惑。 Crockford 的伪经典继承示例如下: var Mammal = function (name) { this.name = n
希望有人能帮我分解 Crockford 的 JS Good Parts 中的一段代码: Function.method('new', function ( ) { // Create a new
在函数式继承模式中,Crockford 引入了一个新的superior 方法: Object.method('superior', function (name) { var that = t
我刚刚看了 Douglas Crockford 的视频,他给出了以下练习: write a function, that when passed a variable, returns a funct
我观看了 YUIConf 2012 的视频,其中 Douglas Crockford 发表了关于在 JavaScript 中实现 monad 的演讲。在本次演讲中,他给出了一个代码示例,该示例使用了他
在接下来的文章中,Douglas Crockford 创建了一个函数来更接近地模拟 JavaScript 中的原型(prototype)继承 (http://javascript.crockford.
在 Douglas Crockford 的 JavaScript: The Good Parts 中,他用这段代码解释了伪经典继承的思想,其中显示 Cat 继承自 Mammal. var Cat =
/** Supplant **/ String.prototype.supplant = function(o) { return this.replace (/{([^{}]*)}/g,
在 Javascript the good parts 一书中,Ch3 on objects 的开篇,它指出: An object is a container of properties, wher
我最近尝试为一个经常创建的值对象优化一些代码。 (三维向量,fwiw) 我尝试的一件事是将构造函数从匿名方法工厂模式转换为普通的 JavaScript 构造函数。 这导致了 severe perfor
只是在 JS 中尝试不同的继承技术,并且发现了一些关于 Crockford 的原型(prototype)继承模式的稍微令人不安的事情: function object(o) { functio
在 Douglas Crockford 的文章中,Private Members in Javascript ,他使用变量“that”来引用“this”,以便在类的特权方法中使用。我一直在我的代码中使
https://github.com/douglascrockford/JSON-js/blob/master/json_parse.js在此链接中,Douglas Crockford 创建了一个 j
我是一名优秀的程序员,十分优秀!