Tag: inheritance

如何覆盖odoo中的js函数

我想加载/购物/结帐url。 function是: odoo.define(‘change_info_order.website_sale_change_info_order’, function (require) { “use strict”; $(‘.oe_website_sale’).each(function () { var oe_website_sale = this; $(oe_website_sale).on(‘click’, ‘a.js_checkout_btn’, function (ev) { var e = document.getElementById(“js_customer_change”); // var customer_id = e.options[e.selectedIndex].value; var customer_id = **e.value**; if (customer_id) { window.location.href = ‘/shop/checkout’; } else { Dialog.alert(self, _t(“Please select the customer”)); }; }); }); }); 我的inheritance代码是: odoo.define(‘website_sale_product_list.website_sale_change_info_order’, function (require) […]

获取inheritanceCSS规则的元素

在jQuery中,我们可以使用css方法轻松获取给定元素的CSS值: $(‘#myElement’).css(‘line-height’); // eg ’16px’ 现在,由于这个CSS值可能是从父元素inheritance的,有没有办法知道哪个元素应用了这个规则? 例如,假设我有以下HTML: 和以下CSS: .parent { line-height: 20px; } 在#myElement上调用css方法将返回20px ,但它不会表明它是从.parentinheritance的。 我知道我可以启动Web Inspector / Dev Tools / Firebug ,但我希望以编程方式获取它。 这是可能吗?

Javascriptinheritance; 电话和原型

要在Javascript中实现inheritance,通常需要执行以下两个步骤; 说我有一个基类“动物” var Animal = function(name){ this.name = name; } 我现在想从同一个派生出一个子类“狗”。 所以我会说 var Dog = function(name) { Animal.call(this,name); } 所以我从派生类构造函数中调用我的父类构造函数。 第二步是将原型设置如下; Dog.prototype = new Animal(); 现在,我可以从派生类Dog中访问任何基本的“Animal”类属性。 所以我的问题是为什么这两个步骤是必要的? 如果我们只是调用基类构造函数 Animal.call(this,name); 实现inheritance还不够吗? 为什么我们还需要使用Dog.prototype = new Animal();来设置prototype属性Dog.prototype = new Animal(); ? 我想了解上述两个步骤的作用是什么?

使用$ .extend和模块模式的简单javascriptinheritance

我想知道几年后人们怎么想用inheritance模块模式 – esque构造函数模式和没有正常的原型inheritance。 为什么程序员不为非单例js类使用模块模式? 对我来说,优点是: 非常明确的公共和私人范围(易于理解代码和API) 无需在回调中通过$ .proxy(fn,this)跟踪’this’指针 不再使用事件处理程序等等= =等等。每当我看到’this’时,我知道它是传递给回调的上下文,它不是我跟踪以了解我的对象实例的东西。 缺点: 小性能退化 道格·克罗克福德可能有“手指摇摆”的风险吗? 考虑一下(只需在任何js控制台中运行) var Animal = function () { var publicApi = { Name: ‘Generic’, IsAnimal: true, AnimalHello: animalHello, GetHelloCount:getHelloCount }; var helloCount = 0; function animalHello() { helloCount++; console.log(publicApi.Name + ‘ says hello (animalHello)’); } function getHelloCount(callback) { callback.call(helloCount); } return publicApi; }; […]

Javascript命名空间

我希望通过将其分成不同的文件并使每个文件成为“子”命名空间来使我的javascript更加模块化。 subA.js if(typeof ex == “undefined”) { var ex = {}; } ex.subA = function() { //all functions of subA here } 对于subB等也一样 目前我有1个文件, ex.js var ex = (function() { //private vars/funcs return { //public vars/funcs } })(); 看起来我应该将我的大多数函数移动到subA.js和subB.js,但在开始时仍然包含ex.js,之后使用subA.js和subB.js。 我有很多问题。 我很难记住我是如何创建初始命名空间文件ex.js. 看起来匿名函数最初是为了使所有东西都是私有的,但我不记得为什么它需要括在括号中然后用();直接执行(); 在末尾。 从q1开始,我的子文件是否应该与ex.js的格式相同,即,将anon函数包含在括号中并立即执行? 看起来子文件只能访问ex的公共函数,这是真的吗? 如果是,我如何允许我的子文件访问私有函数? 在我的HTML文件中,在我的document.ready函数(jQuery)中,我应该将ex初始化为变量还是可以通过继续单独调用每个函数 $(document).ready(function(){ ex.doSomething(); ex.doSomethingElse(); } 这两者有区别吗? 我认为当包含ex.js时,会立即创建一个全局变量ex(由于匿名函数被立即执行),所以我不需要在document.ready中重新定义它。 subA.js中的第一个if语句与var ex […]